Skip to content

Commit 1e34279

Browse files
authored
exporter/otlp: Add instrumentation info to exported spans (#1095)
Fixes #1094
1 parent d7ce152 commit 1e34279

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

exporter/opentelemetry-exporter-otlp/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Add instrumentation info to exported spans
6+
([#1095](https://github.com/open-telemetry/opentelemetry-python/pull/1095))
57
- Add metric OTLP exporter
68
([#835](https://github.com/open-telemetry/opentelemetry-python/pull/835))
79

exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/trace_exporter/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from opentelemetry.proto.collector.trace.v1.trace_service_pb2_grpc import (
2828
TraceServiceStub,
2929
)
30+
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary
3031
from opentelemetry.proto.trace.v1.trace_pb2 import (
3132
InstrumentationLibrarySpans,
3233
ResourceSpans,
@@ -168,9 +169,22 @@ def _translate_data(self, data) -> ExportTraceServiceRequest:
168169
if sdk_span.resource not in (
169170
sdk_resource_instrumentation_library_spans.keys()
170171
):
172+
if sdk_span.instrumentation_info is not None:
173+
instrumentation_library_spans = InstrumentationLibrarySpans(
174+
instrumentation_library=InstrumentationLibrary(
175+
name=sdk_span.instrumentation_info.name,
176+
version=sdk_span.instrumentation_info.version,
177+
)
178+
)
179+
180+
else:
181+
instrumentation_library_spans = (
182+
InstrumentationLibrarySpans()
183+
)
184+
171185
sdk_resource_instrumentation_library_spans[
172186
sdk_span.resource
173-
] = InstrumentationLibrarySpans()
187+
] = instrumentation_library_spans
174188

175189
self._collector_span_kwargs = {}
176190

exporter/opentelemetry-exporter-otlp/tests/test_otlp_trace_exporter.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
TraceServiceServicer,
3131
add_TraceServiceServicer_to_server,
3232
)
33-
from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
33+
from opentelemetry.proto.common.v1.common_pb2 import (
34+
AnyValue,
35+
InstrumentationLibrary,
36+
KeyValue,
37+
)
3438
from opentelemetry.proto.resource.v1.resource_pb2 import (
3539
Resource as CollectorResource,
3640
)
@@ -46,6 +50,7 @@
4650
SimpleExportSpanProcessor,
4751
SpanExportResult,
4852
)
53+
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
4954
from opentelemetry.trace import SpanKind
5055

5156

@@ -142,6 +147,9 @@ def setUp(self):
142147
}
143148
)
144149
],
150+
instrumentation_info=InstrumentationInfo(
151+
name="name", version="version"
152+
),
145153
)
146154

147155
self.span.start()
@@ -209,6 +217,9 @@ def test_translate_spans(self):
209217
),
210218
instrumentation_library_spans=[
211219
InstrumentationLibrarySpans(
220+
instrumentation_library=InstrumentationLibrary(
221+
name="name", version="version"
222+
),
212223
spans=[
213224
CollectorSpan(
214225
# pylint: disable=no-member
@@ -282,7 +293,7 @@ def test_translate_spans(self):
282293
)
283294
],
284295
)
285-
]
296+
],
286297
)
287298
],
288299
),

0 commit comments

Comments
 (0)