diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4f342c3e..1cf86542 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -9,9 +9,10 @@ on: jobs: php: - runs-on: ubuntu-latest + continue-on-error: true strategy: + fail-fast: false matrix: operating-system: [ubuntu-latest] php-version: ['7.4', '8.0', '8.1'] diff --git a/src/Aws/src/Xray/Propagator.php b/src/Aws/src/Xray/Propagator.php index 02ad60bd..96d69d4c 100644 --- a/src/Aws/src/Xray/Propagator.php +++ b/src/Aws/src/Xray/Propagator.php @@ -22,6 +22,7 @@ use OpenTelemetry\API\Trace as API; use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\Context\Context; +use OpenTelemetry\Context\ContextInterface; use OpenTelemetry\Context\Propagation\ArrayAccessGetterSetter; use OpenTelemetry\Context\Propagation\PropagationGetterInterface; use OpenTelemetry\Context\Propagation\PropagationSetterInterface; @@ -72,7 +73,7 @@ public function fields(): array * X-Amzn-Trace-Id: Root={traceId};Parent={parentId};Sampled={samplingFlag} * X-Amzn-Trace-Id: Root=1-5759e988-bd862e3fe1be46a994272793;Parent=53995c3f42cd8ad8;Sampled=1 */ - public function inject(&$carrier, PropagationSetterInterface $setter = null, Context $context = null): void + public function inject(&$carrier, PropagationSetterInterface $setter = null, ContextInterface $context = null): void { $setter = $setter ?? ArrayAccessGetterSetter::getInstance(); $context = $context ?? Context::getCurrent(); @@ -101,7 +102,7 @@ public function inject(&$carrier, PropagationSetterInterface $setter = null, Con * This function will parse all parts of the header and validate that it is * formatted properly to AWS X-ray standards */ - public function extract($carrier, PropagationGetterInterface $getter = null, Context $context = null): Context + public function extract($carrier, PropagationGetterInterface $getter = null, ContextInterface $context = null): ContextInterface { $getter = $getter ?? ArrayAccessGetterSetter::getInstance(); $context = $context ?? Context::getCurrent(); @@ -114,8 +115,8 @@ public function extract($carrier, PropagationGetterInterface $getter = null, Con } $headerComponents = explode(self::TRACE_HEADER_DELIMITER, $traceHeader); - $parsedTraceId = SpanContext::INVALID_TRACE; - $parsedSpanId = SpanContext::INVALID_SPAN; + $parsedTraceId = API\SpanContextValidator::INVALID_TRACE; + $parsedSpanId = API\SpanContextValidator::INVALID_SPAN; $sampledFlag = ''; foreach ($headerComponents as $component) { @@ -157,9 +158,9 @@ public function extract($carrier, PropagationGetterInterface $getter = null, Con */ private function parseTraceId($traceId): string { - $parsedTraceId = SpanContext::INVALID_TRACE; + $parsedTraceId = API\SpanContextValidator::INVALID_TRACE; $traceIdParts = explode(self::TRACE_ID_DELIMITER, $traceId); - if (count($traceIdParts) > 1 && SpanContext::isValidTraceId($traceIdParts[self::TIMESTAMP_INDEX] . + if (count($traceIdParts) > 1 && API\SpanContextValidator::isValidTraceId($traceIdParts[self::TIMESTAMP_INDEX] . $traceIdParts[self::RANDOM_HEX_INDEX]) && $traceIdParts[self::VERSION_NUMBER_INDEX] === self::VERSION_NUMBER) { $parsedTraceId = $traceIdParts[self::TIMESTAMP_INDEX] . $traceIdParts[self::RANDOM_HEX_INDEX]; } diff --git a/src/Aws/tests/Unit/Xray/IdGeneratorTest.php b/src/Aws/tests/Unit/Xray/IdGeneratorTest.php index 4096c84f..ec55eed5 100644 --- a/src/Aws/tests/Unit/Xray/IdGeneratorTest.php +++ b/src/Aws/tests/Unit/Xray/IdGeneratorTest.php @@ -4,7 +4,7 @@ namespace OpenTelemetry\Tests\Aws\Unit\Xray; -use OpenTelemetry\API\Trace\SpanContext; +use OpenTelemetry\API\Trace\SpanContextValidator; use OpenTelemetry\Aws\Xray\IdGenerator; use PHPUnit\Framework\TestCase; @@ -13,7 +13,7 @@ class IdGeneratorTest extends TestCase public function testGeneratedTraceIdIsValid() { $this->assertTrue( - SpanContext::isValidTraceId( + SpanContextValidator::isValidTraceId( (new IdGenerator())->generateTraceId() ) ); @@ -44,7 +44,7 @@ public function testGeneratedTraceIdTimeStampIsCurrent() public function testGeneratedSpanIdIsValid() { $this->assertTrue( - SpanContext::isValidSpanId( + SpanContextValidator::isValidSpanId( (new IdGenerator())->generateSpanId() ) ); diff --git a/src/Aws/tests/Unit/Xray/PropagatorTest.php b/src/Aws/tests/Unit/Xray/PropagatorTest.php index ce113bc7..e5449072 100644 --- a/src/Aws/tests/Unit/Xray/PropagatorTest.php +++ b/src/Aws/tests/Unit/Xray/PropagatorTest.php @@ -6,9 +6,11 @@ use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\API\Trace\SpanContextInterface; +use OpenTelemetry\API\Trace\SpanContextValidator; use OpenTelemetry\API\Trace\TraceState; use OpenTelemetry\Aws\Xray\Propagator; use OpenTelemetry\Context\Context; +use OpenTelemetry\Context\ContextInterface; use OpenTelemetry\SDK\Trace\Span; use PHPUnit\Framework\TestCase; @@ -109,7 +111,7 @@ public function InjectTraceIdWithInvalidSpanContext() $carrier, null, $this->withSpanContext( - SpanContext::create(SpanContext::INVALID_TRACE, SpanContext::INVALID_SPAN, SpanContextInterface::TRACE_FLAG_SAMPLED, new TraceState('vendor1=opaqueValue1')), + SpanContext::create(SpanContextValidator::INVALID_TRACE, SpanContextValidator::INVALID_SPAN, SpanContextInterface::TRACE_FLAG_SAMPLED, new TraceState('vendor1=opaqueValue1')), Context::getCurrent() ) ); @@ -166,8 +168,8 @@ public function ExtractInvalidTraceIdDelimiter() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -183,8 +185,8 @@ public function ExtractEmptySpanContext() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -201,8 +203,8 @@ public function ExtractInvalidSpanContext() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -219,8 +221,8 @@ public function ExtractInvalidTraceId() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -236,8 +238,8 @@ public function ExtractInvalidTraceIdLength() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -253,8 +255,8 @@ public function ExtractInvalidSpanId() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -270,8 +272,8 @@ public function ExtractInvalidSpanIdLength() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -287,8 +289,8 @@ public function ExtractNullSampledValue() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -304,8 +306,8 @@ public function ExtractInvalidSampleValue() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } @@ -321,13 +323,13 @@ public function ExtractInvalidXrayVersion() $carrier = [Propagator::AWSXRAY_TRACE_ID_HEADER => $traceHeader]; $context = Span::fromContext((new Propagator())->extract($carrier))->getContext(); - $this->assertSame(SpanContext::INVALID_TRACE, $context->getTraceId()); - $this->assertSame(SpanContext::INVALID_SPAN, $context->getSpanId()); + $this->assertSame(SpanContextValidator::INVALID_TRACE, $context->getTraceId()); + $this->assertSame(SpanContextValidator::INVALID_SPAN, $context->getSpanId()); $this->assertSame(self::NOT_SAMPLED, ($context->isSampled() ? '1' : '0')); $this->assertFalse($context->isRemote()); } - private function withSpanContext(SpanContextInterface $spanContext, Context $context): Context + private function withSpanContext(SpanContextInterface $spanContext, ContextInterface $context): ContextInterface { return $context->withContextValue(Span::wrap($spanContext)); }