Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Use ArrayHeaders in RequestHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad Stojanovikj committed Mar 28, 2019
1 parent 90f478d commit 707710b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Trace/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OpenCensus\Core\Context;
use OpenCensus\Core\Scope;
use OpenCensus\Trace\Exporter\ExporterInterface;
use OpenCensus\Trace\Propagator\ArrayHeaders;
use OpenCensus\Trace\Sampler\SamplerInterface;
use OpenCensus\Trace\Span;
use OpenCensus\Trace\Tracer\ContextTracer;
Expand Down Expand Up @@ -65,7 +66,7 @@ class RequestHandler
private $scope;

/**
* @var array Replacement $_SERVER variables
* @var ArrayHeaders Keeps the provided headers and has a fallback to $_SERVER if none were given.
*/
private $headers;

Expand All @@ -91,9 +92,7 @@ public function __construct(
array $options = []
) {
$this->exporter = $exporter;
$this->headers = array_key_exists('headers', $options)
? $options['headers']
: $_SERVER;
$this->headers = new ArrayHeaders($options['headers'] ?? $_SERVER);

$spanContext = $propagator->extract($this->headers);

Expand All @@ -113,8 +112,8 @@ public function __construct(
: new NullTracer();

$spanOptions = $options + [
'startTime' => $this->startTimeFromHeaders($this->headers),
'name' => $this->nameFromHeaders($this->headers),
'startTime' => $this->startTimeFromHeaders($this->headers->toArray()),
'name' => $this->nameFromHeaders($this->headers->toArray()),
'attributes' => [],
'kind' => Span::KIND_SERVER,
'sameProcessAsParentSpan' => false
Expand All @@ -134,7 +133,7 @@ public function __construct(
*/
public function onExit()
{
$this->addCommonRequestAttributes($this->headers);
$this->addCommonRequestAttributes($this->headers->toArray());

$this->scope->close();

Expand Down

0 comments on commit 707710b

Please sign in to comment.