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

Commit

Permalink
Merge pull request #18 from nenadstojanovikj/patch-fix-b3-empty-context
Browse files Browse the repository at this point in the history
Fix B3 propagator behavior when an empty context is given
  • Loading branch information
Nenad Stojanovikj authored Apr 2, 2019
2 parents 43eeb34 + a711642 commit 37931cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Trace/Propagator/B3HeadersPropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function extract(HeaderGetter $headers): SpanContext
public function inject(SpanContext $context, HeaderSetter $headers): void
{
$headers->set(self::X_B3_TRACE_ID, $context->traceId());
$headers->set(self::X_B3_SPAN_ID, $context->spanId());
$headers->set(self::X_B3_SPAN_ID, $context->spanId() ?? '');
$headers->set(self::X_B3_SAMPLED, $context->enabled() ? 1 : 0);
}
}
17 changes: 17 additions & 0 deletions tests/unit/Trace/Propagator/B3HeadersPropagatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ public function testInject($traceId, $spanId, $enabled, $headers)
$this->assertEquals($sampled, $output['X-B3-Sampled']);
}

public function testEmptyContext()
{
$propagator = new B3HeadersPropagator();
$context = new SpanContext();
$headers = new ArrayHeaders();
$propagator->inject($context, $headers);
$output = $headers->toArray();

$this->assertArrayHasKey('X-B3-TraceId', $output);
$this->assertArrayHasKey('X-B3-SpanId', $output);
$this->assertArrayHasKey('X-B3-Sampled', $output);

$this->assertNotEmpty($output['X-B3-TraceId']);
$this->assertEquals('', $output['X-B3-SpanId']);
$this->assertEquals(0, $output['X-B3-Sampled']);
}

public function traceMetadata()
{
return [
Expand Down

0 comments on commit 37931cd

Please sign in to comment.