[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added B3MultiPropagater #680

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored B3MultiPropagator and added tests in B3MultiPropagatorTest
  • Loading branch information
kishannsangani committed May 25, 2022
commit 357a18ca79878595d90a34df29068d13250111af
2 changes: 1 addition & 1 deletion src/API/Trace/Propagation/B3MultiPropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static function extractImpl($carrier, PropagationGetterInterface $getter
return SpanContext::getInvalid();
}

$isSampled = ($sampled && $sampled === SpanContext::SAMPLED_FLAG);
$isSampled = ($sampled === SpanContext::SAMPLED_FLAG);

// Only traceparent header is extracted. No tracestate.
return SpanContext::createFromRemoteParent(
Expand Down
60 changes: 56 additions & 4 deletions tests/Unit/API/Trace/Propagation/B3MultiPropagatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ public function test_extract_nothing(): void
);
}

public function test_extract_sampled_context(): void
/**
* @dataProvider sampledValueProvider
*/
public function test_extract_sampled_context($sampledValue): void
{
$carrier = $this->getLowerCaseKeys([
B3MultiPropagator::TRACE_ID => self::TRACE_ID_BASE16,
B3MultiPropagator::SPAN_ID => self::SPAN_ID_BASE16,
B3MultiPropagator::SAMPLED => self::IS_SAMPLED,
B3MultiPropagator::SAMPLED => $sampledValue,
]);

$this->assertEquals(
Expand All @@ -133,12 +136,52 @@ public function test_extract_sampled_context(): void
);
}

public function test_extract_non_sampled_context(): void
public function sampledValueProvider()
{
return [
'String sampled value' => ['1'],
'Boolean(lower string) sampled value' => ['true'],
'Boolean(upper string) sampled value' => ['TRUE'],
'Boolean(camel string) sampled value' => ['True'],
];
}

/**
* @dataProvider notSampledValueProvider
*/
public function test_extract_non_sampled_context($sampledValue): void
{
$carrier = $this->getLowerCaseKeys([
B3MultiPropagator::TRACE_ID => self::TRACE_ID_BASE16,
B3MultiPropagator::SPAN_ID => self::SPAN_ID_BASE16,
B3MultiPropagator::SAMPLED => $sampledValue,
]);

$this->assertEquals(
SpanContext::createFromRemoteParent(self::TRACE_ID_BASE16, self::SPAN_ID_BASE16),
$this->getSpanContext($this->b3MultiPropagator->extract($carrier))
);
}

public function notSampledValueProvider()
{
return [
'String sampled value' => ['0'],
'Boolean(lower string) sampled value' => ['false'],
'Boolean(upper string) sampled value' => ['FALSE'],
'Boolean(camel string) sampled value' => ['False'],
];
}

/**
* @dataProvider invalidSampledValueProvider
*/
public function test_extract_invalid_sampled_context($sampledValue): void
{
$carrier = $this->getLowerCaseKeys([
B3MultiPropagator::TRACE_ID => self::TRACE_ID_BASE16,
B3MultiPropagator::SPAN_ID => self::SPAN_ID_BASE16,
B3MultiPropagator::SAMPLED => self::IS_NOT_SAMPLED,
B3MultiPropagator::SAMPLED => $sampledValue,
]);

$this->assertEquals(
Expand All @@ -147,6 +190,15 @@ public function test_extract_non_sampled_context(): void
);
}

public function invalidSampledValueProvider()
{
return [
'wrong sampled value' => ['wrong'],
'null sampled value' => [null],
'empty sampled value' => [[]],
];
}

public function test_extract_and_inject(): void
{
$extractCarrier = $this->getLowerCaseKeys([
Expand Down