Skip to content

Commit

Permalink
exporter/otlp: Add instrumentation info to exported spans (open-telem…
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Sep 14, 2020
1 parent d7ce152 commit 1e34279
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions exporter/opentelemetry-exporter-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from opentelemetry.proto.collector.trace.v1.trace_service_pb2_grpc import (
TraceServiceStub,
)
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary
from opentelemetry.proto.trace.v1.trace_pb2 import (
InstrumentationLibrarySpans,
ResourceSpans,
Expand Down Expand Up @@ -168,9 +169,22 @@ def _translate_data(self, data) -> ExportTraceServiceRequest:
if sdk_span.resource not in (
sdk_resource_instrumentation_library_spans.keys()
):
if sdk_span.instrumentation_info is not None:
instrumentation_library_spans = InstrumentationLibrarySpans(
instrumentation_library=InstrumentationLibrary(
name=sdk_span.instrumentation_info.name,
version=sdk_span.instrumentation_info.version,
)
)

else:
instrumentation_library_spans = (
InstrumentationLibrarySpans()
)

sdk_resource_instrumentation_library_spans[
sdk_span.resource
] = InstrumentationLibrarySpans()
] = instrumentation_library_spans

self._collector_span_kwargs = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
TraceServiceServicer,
add_TraceServiceServicer_to_server,
)
from opentelemetry.proto.common.v1.common_pb2 import AnyValue, KeyValue
from opentelemetry.proto.common.v1.common_pb2 import (
AnyValue,
InstrumentationLibrary,
KeyValue,
)
from opentelemetry.proto.resource.v1.resource_pb2 import (
Resource as CollectorResource,
)
Expand All @@ -46,6 +50,7 @@
SimpleExportSpanProcessor,
SpanExportResult,
)
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
from opentelemetry.trace import SpanKind


Expand Down Expand Up @@ -142,6 +147,9 @@ def setUp(self):
}
)
],
instrumentation_info=InstrumentationInfo(
name="name", version="version"
),
)

self.span.start()
Expand Down Expand Up @@ -209,6 +217,9 @@ def test_translate_spans(self):
),
instrumentation_library_spans=[
InstrumentationLibrarySpans(
instrumentation_library=InstrumentationLibrary(
name="name", version="version"
),
spans=[
CollectorSpan(
# pylint: disable=no-member
Expand Down Expand Up @@ -282,7 +293,7 @@ def test_translate_spans(self):
)
],
)
]
],
)
],
),
Expand Down

0 comments on commit 1e34279

Please sign in to comment.