Skip to content

Commit

Permalink
Amend Span tests (#51)
Browse files Browse the repository at this point in the history
* Amend Span tests

* Removed no longer used stuff
  • Loading branch information
sergeyklay authored and jonahgeorge committed Jul 27, 2018
1 parent 618341d commit 6e049c3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/Jaeger/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Span implements OTSpan
*/
public $peer;

/**
* @var string|null
*/
private $component;

/**
Expand Down Expand Up @@ -200,6 +203,9 @@ public function overwriteOperationName($newOperationName)

/**
* {@inheritdoc}
*
* @param array|\Traversable $tags
* @return void
*/
public function setTags($tags)
{
Expand All @@ -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;
Expand All @@ -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
Expand Down
43 changes: 39 additions & 4 deletions tests/Jaeger/SpanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');

Expand Down

0 comments on commit 6e049c3

Please sign in to comment.