diff --git a/src/Jaeger/Span.php b/src/Jaeger/Span.php index 4bb330f..5a15cdd 100644 --- a/src/Jaeger/Span.php +++ b/src/Jaeger/Span.php @@ -54,6 +54,9 @@ class Span implements OTSpan */ public $peer; + /** + * @var string|null + */ private $component; /** @@ -200,6 +203,9 @@ public function overwriteOperationName($newOperationName) /** * {@inheritdoc} + * + * @param array|\Traversable $tags + * @return void */ public function setTags($tags) { @@ -213,9 +219,6 @@ public function setTags($tags) */ public function setTag($key, $value) { -// if ($key == SAMPLING_PRIORITY) { -// } - if ($this->isSampled()) { $special = self::SPECIAL_TAGS[$key] ?? null; $handled = false; @@ -242,6 +245,12 @@ public function setTag($key, $value) ]; /** + * Sets a low-cardinality identifier of the module, library, + * or package that is generating a span. + * + * @see Span::setTag() + * + * @param string $value * @return bool */ private function setComponent($value): bool diff --git a/tests/Jaeger/SpanTest.php b/tests/Jaeger/SpanTest.php index 8e08e19..63afd54 100644 --- a/tests/Jaeger/SpanTest.php +++ b/tests/Jaeger/SpanTest.php @@ -18,13 +18,48 @@ class SpanTest extends TestCase */ private $context; - function setUp() + /** + * {@inheritdoc} + */ + public function setUp() { $this->tracer = new Tracer('test-service', new NullReporter, new ConstSampler); $this->context = new SpanContext(0, 0,0, SAMPLED_FLAG); } - function testSetTag_TagsKeysAreUnique() + /** @test */ + public function shouldSetComponentThroughTag() + { + $span = new Span($this->context, $this->tracer, 'test-operation'); + + $span->setTag('component', 'libredis'); + + $spanReflection = new \ReflectionClass(Span::class); + $component = $spanReflection->getProperty('component'); + $component->setAccessible(true); + + $this->assertEquals( 0, count($span->getTags())); + $this->assertEquals( 'libredis', $component->getValue($span)); + } + + /** @test */ + public function shouldSetTags() + { + $span = new Span($this->context, $this->tracer, 'test-operation'); + + $this->assertEquals( 0, count($span->getTags())); + + $span->setTags([ + 'foo-1' => 'test-component-1', + 'foo-2' => 'test-component-2', + 'foo-3' => 'test-component-3', + ]); + + $this->assertEquals( 3, count($span->getTags())); + } + + /** @test */ + public function shouldOverwriteTheSameTag() { // Given $span = new Span($this->context, $this->tracer, 'test-operation'); @@ -37,8 +72,8 @@ function testSetTag_TagsKeysAreUnique() $this->assertEquals( 1, count($span->getTags())); $this->assertEquals( 'test-component-2', $span->getTags()['foo']->value); } - - public function testLog() + /** @test */ + public function shouldAddLogRecordsToTheSpan() { $span = new Span($this->context, $this->tracer, 'test-operation');