diff --git a/exporter/opentelemetry-exporter-otlp/CHANGELOG.md b/exporter/opentelemetry-exporter-otlp/CHANGELOG.md index e467d8f78e9..074a30bbc5b 100644 --- a/exporter/opentelemetry-exporter-otlp/CHANGELOG.md +++ b/exporter/opentelemetry-exporter-otlp/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Add instrumentation library name and version to OTLP exported metrics + ([#1418](https://github.com/open-telemetry/opentelemetry-python/pull/1418)) - Change temporality for Counter and UpDownCounter ([#1384](https://github.com/open-telemetry/opentelemetry-python/pull/1384)) - Add Gzip compression for exporter diff --git a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py index c90dd47db27..b861efb3126 100644 --- a/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py @@ -304,9 +304,11 @@ def _translate_data( ) argument = type_class[value_type]["gauge"]["argument"] - sdk_resource_instrumentation_library_metrics[ + instrumentation_library_metrics = sdk_resource_instrumentation_library_metrics[ export_record.resource - ].metrics.append( + ] + + instrumentation_library_metrics.metrics.append( OTLPMetric( **{ "name": export_record.instrument.name, @@ -317,6 +319,13 @@ def _translate_data( ) ) + instrumentation_library_metrics.instrumentation_library.name = ( + export_record.instrument.meter.instrumentation_info.name + ) + instrumentation_library_metrics.instrumentation_library.version = ( + export_record.instrument.meter.instrumentation_info.version + ) + return ExportMetricsServiceRequest( resource_metrics=_get_resource_data( sdk_resource_instrumentation_library_metrics, diff --git a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py index 308d217f21b..c255d91ec70 100644 --- a/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py +++ b/exporter/opentelemetry-exporter-otlp/tests/test_otlp_metric_exporter.py @@ -26,6 +26,7 @@ ) from opentelemetry.proto.common.v1.common_pb2 import ( AnyValue, + InstrumentationLibrary, KeyValue, StringKeyValue, ) @@ -61,7 +62,7 @@ def setUp(self, mock_time_ns): # pylint: disable=arguments-differ "d", "e", int, - MeterProvider(resource=resource,).get_meter(__name__), + MeterProvider(resource=resource,).get_meter("name", "version"), ("f",), ), [("g", "h")], @@ -121,6 +122,9 @@ def test_translate_metrics(self): ), instrumentation_library_metrics=[ InstrumentationLibraryMetrics( + instrumentation_library=InstrumentationLibrary( + name="name", version="version", + ), metrics=[ OTLPMetric( name="c", @@ -145,7 +149,7 @@ def test_translate_metrics(self): is_monotonic=True, ), ) - ] + ], ) ], )