export otlp InstrumentationScope attributes (#825)
* export otlp InstrumentationScope attributes * remove redundant setting of dropped attributes count
This commit is contained in:
parent
84142d35e9
commit
b551294d3f
|
@ -95,6 +95,7 @@ final class MetricConverter
|
||||||
$pInstrumentationScope = new InstrumentationScope();
|
$pInstrumentationScope = new InstrumentationScope();
|
||||||
$pInstrumentationScope->setName($instrumentationScope->getName());
|
$pInstrumentationScope->setName($instrumentationScope->getName());
|
||||||
$pInstrumentationScope->setVersion((string) $instrumentationScope->getVersion());
|
$pInstrumentationScope->setVersion((string) $instrumentationScope->getVersion());
|
||||||
|
$this->setAttributes($pInstrumentationScope, $instrumentationScope->getAttributes());
|
||||||
$pScopeMetrics->setScope($pInstrumentationScope);
|
$pScopeMetrics->setScope($pInstrumentationScope);
|
||||||
$pScopeMetrics->setSchemaUrl((string) $instrumentationScope->getSchemaUrl());
|
$pScopeMetrics->setSchemaUrl((string) $instrumentationScope->getSchemaUrl());
|
||||||
|
|
||||||
|
@ -230,7 +231,7 @@ final class MetricConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Resource_|NumberDataPoint|HistogramDataPoint $pElement
|
* @param Resource_|NumberDataPoint|HistogramDataPoint|InstrumentationScope $pElement
|
||||||
*/
|
*/
|
||||||
private function setAttributes($pElement, SDK\Common\Attribute\AttributesInterface $attributes): void
|
private function setAttributes($pElement, SDK\Common\Attribute\AttributesInterface $attributes): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,6 +92,7 @@ final class SpanConverter
|
||||||
$pInstrumentationScope = new InstrumentationScope();
|
$pInstrumentationScope = new InstrumentationScope();
|
||||||
$pInstrumentationScope->setName($instrumentationScope->getName());
|
$pInstrumentationScope->setName($instrumentationScope->getName());
|
||||||
$pInstrumentationScope->setVersion((string) $instrumentationScope->getVersion());
|
$pInstrumentationScope->setVersion((string) $instrumentationScope->getVersion());
|
||||||
|
$this->setAttributes($pInstrumentationScope, $instrumentationScope->getAttributes());
|
||||||
$pScopeSpans->setScope($pInstrumentationScope);
|
$pScopeSpans->setScope($pInstrumentationScope);
|
||||||
$pScopeSpans->setSchemaUrl((string) $instrumentationScope->getSchemaUrl());
|
$pScopeSpans->setSchemaUrl((string) $instrumentationScope->getSchemaUrl());
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ final class SpanConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Resource_|Span|Event|Link $pElement
|
* @param Resource_|Span|Event|Link|InstrumentationScope $pElement
|
||||||
*/
|
*/
|
||||||
private function setAttributes($pElement, AttributesInterface $attributes): void
|
private function setAttributes($pElement, AttributesInterface $attributes): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -205,4 +205,28 @@ final class MetricConverterTest extends TestCase
|
||||||
])->getResourceMetrics(),
|
])->getResourceMetrics(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_instrumentation_scope_is_converted(): void
|
||||||
|
{
|
||||||
|
$this->assertJsonStringEqualsJsonString(
|
||||||
|
<<<JSON
|
||||||
|
{"resourceMetrics": [{"resource": {},"scopeMetrics": [{
|
||||||
|
"metrics": [{"description": "description-1","name": "name-1","unit": "unit-1"}],
|
||||||
|
"schemaUrl": "http://schema.url",
|
||||||
|
"scope": {"attributes": [{"key": "foo","value": {"stringValue": "bar"}}],"name": "scope-name","version": "scope-version"}
|
||||||
|
}
|
||||||
|
]}]}
|
||||||
|
JSON,
|
||||||
|
(new MetricConverter())->convert([
|
||||||
|
new Metric(
|
||||||
|
new InstrumentationScope('scope-name', 'scope-version', 'http://schema.url', Attributes::create(['foo' => 'bar'])),
|
||||||
|
ResourceInfoFactory::emptyResource(),
|
||||||
|
'name-1',
|
||||||
|
'unit-1',
|
||||||
|
'description-1',
|
||||||
|
$this->createMock(DataInterface::class),
|
||||||
|
),
|
||||||
|
])->serializeToJsonString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ class OTLPSpanConverterTest extends TestCase
|
||||||
->setStartEpochNanos($start_time)
|
->setStartEpochNanos($start_time)
|
||||||
->setEndEpochNanos($end_time)
|
->setEndEpochNanos($end_time)
|
||||||
->setName('http_get')
|
->setName('http_get')
|
||||||
->setInstrumentationScope(new InstrumentationScope('lib-test', 'v0.1.0', 'http://url', Attributes::create([])))
|
->setInstrumentationScope(new InstrumentationScope('lib-test', 'v0.1.0', 'http://url', Attributes::create(['foo' => 'bar'])))
|
||||||
->addAttribute('user', 'alice')
|
->addAttribute('user', 'alice')
|
||||||
->addAttribute('authenticated', true)
|
->addAttribute('authenticated', true)
|
||||||
->addEvent('Event1', Attributes::create(['success' => 'yes']), 1617313804325769955)
|
->addEvent('Event1', Attributes::create(['success' => 'yes']), 1617313804325769955)
|
||||||
|
@ -204,6 +204,12 @@ class OTLPSpanConverterTest extends TestCase
|
||||||
'scope' => new \Opentelemetry\Proto\Common\V1\InstrumentationScope([
|
'scope' => new \Opentelemetry\Proto\Common\V1\InstrumentationScope([
|
||||||
'name' => 'lib-test',
|
'name' => 'lib-test',
|
||||||
'version' => 'v0.1.0',
|
'version' => 'v0.1.0',
|
||||||
|
'attributes' => [
|
||||||
|
new KeyValue([
|
||||||
|
'key' => 'foo',
|
||||||
|
'value' => new AnyValue(['string_value' => 'bar']),
|
||||||
|
]),
|
||||||
|
],
|
||||||
]),
|
]),
|
||||||
'spans' => [
|
'spans' => [
|
||||||
new V1\Span([
|
new V1\Span([
|
||||||
|
|
Loading…
Reference in New Issue