Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for tracing compliance #662

Merged
merged 9 commits into from
Apr 17, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions tests/Integration/SDK/SpanBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ protected function setUp(): void
);
}

/**
* @group trace-compliance
*/
public function test_add_link(): void
{
/** @var Span $span */
Expand Down Expand Up @@ -162,6 +165,9 @@ public function test_add_link_truncate_link_attribute_value(): void
$span->end();
tidal marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @group trace-compliance
*/
public function test_add_link_no_effect_after_start_span(): void
{
$spanBuilder = $this->tracer->spanBuilder(self::SPAN_NAME);
Expand All @@ -187,6 +193,9 @@ public function test_add_link_no_effect_after_start_span(): void
$span->end();
tidal marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @group trace-compliance
*/
public function test_set_attribute(): void
{
/** @var Span $span */
Expand All @@ -212,6 +221,9 @@ public function test_set_attribute(): void
$span->end();
tidal marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @group trace-compliance
*/
public function test_set_attribute_after_end(): void
{
/** @var Span $span */
Expand All @@ -230,6 +242,71 @@ public function test_set_attribute_after_end(): void
$span->end();
yuktea marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @group trace-compliance
*/
// public function test_set_attribute_empty_string_value_is_set(): void
// {
// /** @var Span $span */
// $span = $this
// ->tracer
// ->spanBuilder(self::SPAN_NAME)
// ->setAttribute('nil', null)
// ->setAttribute('empty-string', '')
// ->startSpan();

// $attributes = $span->toSpanData()->getAttributes();
// $this->assertSame(1, $attributes->count());
// $this->assertSame('', $attributes->get('empty-string'));
// $this->assertNull($attributes->get('nil'));

// $span->end();
// }

/**
* @group trace-compliance
*/
public function test_set_attribute_only_null_string_value_should_not_be_set(): void
{
/** @var Span $span */
$span = $this
->tracer
->spanBuilder(self::SPAN_NAME)
->setAttribute('nil', null)
->startSpan();

$attributes = $span->toSpanData()->getAttributes();
$this->assertEmpty($span->toSpanData()->getAttributes());
$this->assertNull($attributes->get('nil'));

$span->end();
tidal marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @group trace-compliance
*/
public function test_set_attribute_no_effect_after_start_span(): void
{
$spanBuilder = $this->tracer->spanBuilder(self::SPAN_NAME);

/** @var Span $span */
$span = $spanBuilder
->setAttribute('foo', 'bar')
->setAttribute('bar', 123)
->startSpan();

$attributes = $span->toSpanData()->getAttributes();
$this->assertSame(2, $attributes->count());

$spanBuilder
->setAttribute('bar1', 77);

$attributes = $span->toSpanData()->getAttributes();
$this->assertSame(2, $attributes->count());
yuktea marked this conversation as resolved.
Show resolved Hide resolved

$span->end();
tidal marked this conversation as resolved.
Show resolved Hide resolved
}

public function test_set_attribute_dropping(): void
{
$maxNumberOfAttributes = 8;
Expand Down Expand Up @@ -303,6 +380,34 @@ public function test_set_attributes(): void
$span->end();
}

/**
* @group trace-compliance
*/
public function test_set_attributes_merges_attributes_correctly(): void
{
$attributes = new Attributes(['id' => 2, 'foo' => 'bar', 'key' => 'val']);

/** @var Span $span */
$span = $this
->tracer
->spanBuilder(self::SPAN_NAME)
->setAttribute('key2', 'val2')
->setAttribute('key1', 'val1')
->setAttributes($attributes)
->startSpan();

$attributes = $span->toSpanData()->getAttributes();

$this->assertSame(5, $attributes->count());
$this->assertSame('bar', $attributes->get('foo'));
$this->assertSame(2, $attributes->get('id'));
$this->assertSame('val', $attributes->get('key'));
$this->assertSame('val2', $attributes->get('key2'));
$this->assertSame('val1', $attributes->get('key1'));

$span->end();
}

public function test_set_attributes_overrides_values(): void
{
$attributes = new Attributes(['id' => 1, 'foo' => 'bar']);
Expand Down