From ad119f2f75ce03ab963c9ab6ddaa39d09e0fa1ad Mon Sep 17 00:00:00 2001 From: Jonah George <jonah.george@me.com> Date: Tue, 5 Dec 2017 11:31:21 -0500 Subject: [PATCH] opentracing/opentracing#1.0.0-beta2 --- composer.json | 2 +- src/Jaeger/Tracer.php | 19 +++++++++++++------ tests/ReporterTest.php | 5 +++-- tests/SpanContextTest.php | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/SpanContextTest.php diff --git a/composer.json b/composer.json index a6f90e4..83504c6 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=7.0", "packaged/thrift": "0.10.0", - "opentracing/opentracing" : "dev-master#88ad53393dd3dff3c1d9698f72ec42a907eb4054", + "opentracing/opentracing" : "1.0.0-beta2", "monolog/monolog": "^1.0" }, "require-dev": { diff --git a/src/Jaeger/Tracer.php b/src/Jaeger/Tracer.php index be608d0..f12b261 100644 --- a/src/Jaeger/Tracer.php +++ b/src/Jaeger/Tracer.php @@ -15,9 +15,9 @@ use OpenTracing; use const OpenTracing\Ext\Tags\SPAN_KIND; use const OpenTracing\Ext\Tags\SPAN_KIND_RPC_SERVER; -use const OpenTracing\Propagation\Formats\BINARY; -use const OpenTracing\Propagation\Formats\HTTP_HEADERS; -use const OpenTracing\Propagation\Formats\TEXT_MAP; +use const OpenTracing\Formats\BINARY; +use const OpenTracing\Formats\HTTP_HEADERS; +use const OpenTracing\Formats\TEXT_MAP; use OpenTracing\Propagation\Reader; use OpenTracing\Propagation\Writer; use Psr\Log\LoggerInterface; @@ -107,6 +107,13 @@ public function __construct( } } + public function setSampler(SamplerInterface $sampler) + { + $this->sampler = $sampler; + + return $this; + } + public function getServiceName(): string { return $this->serviceName; @@ -141,7 +148,7 @@ public function startSpan($operationName, $options = []) $parent = $parent->getContext(); } - $rpcServer = ($tags !== null) && + $rpcServer = ($tags !== null) && ($tags[SPAN_KIND] ?? null) == SPAN_KIND_RPC_SERVER; if ($parent === null || $parent->isDebugIdContainerOnly()) { @@ -210,7 +217,7 @@ public function startSpan($operationName, $options = []) * @throws UnsupportedFormat when the format is not recognized by the tracer * implementation */ - public function inject(OpenTracing\SpanContext $spanContext, $format, Writer $carrier) + public function inject(OpenTracing\SpanContext $spanContext, $format, &$carrier) { $codec = $this->codecs[$format] ?? null; if ($codec === null) { @@ -228,7 +235,7 @@ public function inject(OpenTracing\SpanContext $spanContext, $format, Writer $ca * @throws UnsupportedFormat when the format is not recognized by the tracer * implementation */ - public function extract($format, Reader $carrier) + public function extract($format, $carrier) { $codec = $this->codecs[$format] ?? null; if ($codec === null) { diff --git a/tests/ReporterTest.php b/tests/ReporterTest.php index 62f5dcf..b646419 100644 --- a/tests/ReporterTest.php +++ b/tests/ReporterTest.php @@ -5,7 +5,7 @@ use Jaeger\Reporter\NullReporter; use Jaeger\Span; use \PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; class ReporterTest extends TestCase { @@ -32,12 +32,13 @@ public function testInMemoryReporter() public function testLoggingReporter() { - $logger = $this->createMock(LoggerInterface::class); + $logger = $this->createMock(NullLogger::class); $span = $this->createMock(Span::class); $reporter = new LoggingReporter($logger); $logger->method('info') ->with($this->stringStartsWith('Reporting span')); + $reporter->reportSpan($span); } } \ No newline at end of file diff --git a/tests/SpanContextTest.php b/tests/SpanContextTest.php new file mode 100644 index 0000000..8a75818 --- /dev/null +++ b/tests/SpanContextTest.php @@ -0,0 +1,17 @@ +<?php + +use Jaeger\SpanContext; +use PHPUnit\Framework\TestCase; + +class SpanContextTest extends TestCase +{ + public function test_is_debug_id_container_only() + { + $ctx = SpanContext::withDebugId('value1'); + $this->assertTrue($ctx->isDebugIdContainerOnly()); + $this->assertEquals($ctx->getDebugId(), 'value1'); + + $ctx = new SpanContext(1, 2, 3, 1); + $this->assertFalse($ctx->isDebugIdContainerOnly()); + } +} \ No newline at end of file