Skip to content

Commit d48c672

Browse files
committed
Add instrumentation library name and version to OTLP exported metrics
Fixes #1417
1 parent da7597c commit d48c672

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Diff for: exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ def _translate_data(
304304
)
305305
argument = type_class[value_type]["gauge"]["argument"]
306306

307-
sdk_resource_instrumentation_library_metrics[
307+
instrumentation_library_metrics = sdk_resource_instrumentation_library_metrics[
308308
export_record.resource
309-
].metrics.append(
309+
]
310+
311+
instrumentation_library_metrics.metrics.append(
310312
OTLPMetric(
311313
**{
312314
"name": export_record.instrument.name,
@@ -317,6 +319,13 @@ def _translate_data(
317319
)
318320
)
319321

322+
instrumentation_library_metrics.instrumentation_library.name = (
323+
export_record.instrument.meter.instrumentation_info.name
324+
)
325+
instrumentation_library_metrics.instrumentation_library.version = (
326+
export_record.instrument.meter.instrumentation_info.version
327+
)
328+
320329
return ExportMetricsServiceRequest(
321330
resource_metrics=_get_resource_data(
322331
sdk_resource_instrumentation_library_metrics,

Diff for: exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from opentelemetry.proto.common.v1.common_pb2 import (
2828
AnyValue,
29+
InstrumentationLibrary,
2930
KeyValue,
3031
StringKeyValue,
3132
)
@@ -61,7 +62,7 @@ def setUp(self, mock_time_ns): # pylint: disable=arguments-differ
6162
"d",
6263
"e",
6364
int,
64-
MeterProvider(resource=resource,).get_meter(__name__),
65+
MeterProvider(resource=resource,).get_meter("name", "version"),
6566
("f",),
6667
),
6768
[("g", "h")],
@@ -121,6 +122,9 @@ def test_translate_metrics(self):
121122
),
122123
instrumentation_library_metrics=[
123124
InstrumentationLibraryMetrics(
125+
instrumentation_library=InstrumentationLibrary(
126+
name="name", version="version",
127+
),
124128
metrics=[
125129
OTLPMetric(
126130
name="c",
@@ -145,7 +149,7 @@ def test_translate_metrics(self):
145149
is_monotonic=True,
146150
),
147151
)
148-
]
152+
],
149153
)
150154
],
151155
)

0 commit comments

Comments
 (0)