Skip to content

Commit

Permalink
Fixing build failures (#85)
Browse files Browse the repository at this point in the history
* fixing aws for 0.0.16
update to use ContextInterface and SpanContextValidator
* don't fail fast on build errors
  • Loading branch information
brettmc authored Nov 17, 2022
1 parent f0e6db3 commit e34f242
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
13 changes: 7 additions & 6 deletions src/Aws/src/Xray/Propagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Aws/tests/Unit/Xray/IdGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,7 +13,7 @@ class IdGeneratorTest extends TestCase
public function testGeneratedTraceIdIsValid()
{
$this->assertTrue(
SpanContext::isValidTraceId(
SpanContextValidator::isValidTraceId(
(new IdGenerator())->generateTraceId()
)
);
Expand Down Expand Up @@ -44,7 +44,7 @@ public function testGeneratedTraceIdTimeStampIsCurrent()
public function testGeneratedSpanIdIsValid()
{
$this->assertTrue(
SpanContext::isValidSpanId(
SpanContextValidator::isValidSpanId(
(new IdGenerator())->generateSpanId()
)
);
Expand Down
46 changes: 24 additions & 22 deletions src/Aws/tests/Unit/Xray/PropagatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
)
);
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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));
}
Expand Down

0 comments on commit e34f242

Please sign in to comment.