Include schema_url in FriendlySpanConverter (#1292)
This commit is contained in:
parent
cea2d7c4cb
commit
9fe6aa0cd7
|
|
@ -35,6 +35,7 @@ class FriendlySpanConverter implements SpanConverterInterface
|
||||||
private const EVENTS_ATTR = 'events';
|
private const EVENTS_ATTR = 'events';
|
||||||
private const TIMESTAMP_ATTR = 'timestamp';
|
private const TIMESTAMP_ATTR = 'timestamp';
|
||||||
private const LINKS_ATTR = 'links';
|
private const LINKS_ATTR = 'links';
|
||||||
|
private const SCHEMA_URL_ATTR = 'schema_url';
|
||||||
|
|
||||||
public function convert(iterable $spans): array
|
public function convert(iterable $spans): array
|
||||||
{
|
{
|
||||||
|
|
@ -63,6 +64,7 @@ class FriendlySpanConverter implements SpanConverterInterface
|
||||||
self::STATUS_ATTR => $this->covertStatus($span->getStatus()),
|
self::STATUS_ATTR => $this->covertStatus($span->getStatus()),
|
||||||
self::EVENTS_ATTR => $this->convertEvents($span->getEvents()),
|
self::EVENTS_ATTR => $this->convertEvents($span->getEvents()),
|
||||||
self::LINKS_ATTR => $this->convertLinks($span->getLinks()),
|
self::LINKS_ATTR => $this->convertLinks($span->getLinks()),
|
||||||
|
self::SCHEMA_URL_ATTR => $this->convertSchemaUrl($span->getInstrumentationScope()->getSchemaUrl()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,4 +146,12 @@ class FriendlySpanConverter implements SpanConverterInterface
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|null $schemaUrl
|
||||||
|
*/
|
||||||
|
private function convertSchemaUrl(?string $schemaUrl): string
|
||||||
|
{
|
||||||
|
return $schemaUrl ?? '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use OpenTelemetry\API\Trace\SpanContextInterface;
|
||||||
use OpenTelemetry\API\Trace\SpanKind;
|
use OpenTelemetry\API\Trace\SpanKind;
|
||||||
use OpenTelemetry\API\Trace\TraceStateInterface;
|
use OpenTelemetry\API\Trace\TraceStateInterface;
|
||||||
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
|
use OpenTelemetry\SDK\Common\Attribute\AttributesInterface;
|
||||||
|
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
|
||||||
use OpenTelemetry\SDK\Resource\ResourceInfo;
|
use OpenTelemetry\SDK\Resource\ResourceInfo;
|
||||||
use OpenTelemetry\SDK\Trace\EventInterface;
|
use OpenTelemetry\SDK\Trace\EventInterface;
|
||||||
use OpenTelemetry\SDK\Trace\LinkInterface;
|
use OpenTelemetry\SDK\Trace\LinkInterface;
|
||||||
|
|
@ -78,6 +79,7 @@ class FriendlySpanConverterTest extends TestCase
|
||||||
'foz' => 'baz',
|
'foz' => 'baz',
|
||||||
], ],
|
], ],
|
||||||
],
|
],
|
||||||
|
'schema_url' => 'https://opentelemetry.io/schemas/1.25.0',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function test_convert(): void
|
public function test_convert(): void
|
||||||
|
|
@ -160,9 +162,23 @@ class FriendlySpanConverterTest extends TestCase
|
||||||
}
|
}
|
||||||
$mock->method('getLinks')->willReturn($links);
|
$mock->method('getLinks')->willReturn($links);
|
||||||
|
|
||||||
|
$mock->method('getInstrumentationScope')
|
||||||
|
->willReturn(
|
||||||
|
$this->createInstrumentationScopeMock()
|
||||||
|
);
|
||||||
|
|
||||||
return $mock;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createInstrumentationScopeMock(): InstrumentationScopeInterface
|
||||||
|
{
|
||||||
|
$mock = $this->createMock(InstrumentationScopeInterface::class);
|
||||||
|
|
||||||
|
$mock->method('getSchemaUrl')
|
||||||
|
->willReturn($this->createSchemaUrlMock());
|
||||||
|
|
||||||
|
return $mock;
|
||||||
|
}
|
||||||
private function createSpanContextMock(string $spanId, string $traceId = '0', string $traceState = null): SpanContextInterface
|
private function createSpanContextMock(string $spanId, string $traceId = '0', string $traceState = null): SpanContextInterface
|
||||||
{
|
{
|
||||||
$mock = $this->createMock(SpanContextInterface::class);
|
$mock = $this->createMock(SpanContextInterface::class);
|
||||||
|
|
@ -249,4 +265,9 @@ class FriendlySpanConverterTest extends TestCase
|
||||||
|
|
||||||
return $mock;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createSchemaUrlMock(): string
|
||||||
|
{
|
||||||
|
return self::TEST_DATA['schema_url'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue