Skip to content

Commit

Permalink
Add instrumentation library name and version to OTLP exported metrics
Browse files Browse the repository at this point in the history
Fixes #1417
  • Loading branch information
ocelotl committed Nov 25, 2020
1 parent da7597c commit 0d3bce2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 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 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from opentelemetry.proto.common.v1.common_pb2 import (
AnyValue,
InstrumentationLibrary,
KeyValue,
StringKeyValue,
)
Expand Down Expand Up @@ -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")],
Expand Down Expand Up @@ -121,6 +122,9 @@ def test_translate_metrics(self):
),
instrumentation_library_metrics=[
InstrumentationLibraryMetrics(
instrumentation_library=InstrumentationLibrary(
name="name", version="version",
),
metrics=[
OTLPMetric(
name="c",
Expand All @@ -145,7 +149,7 @@ def test_translate_metrics(self):
is_monotonic=True,
),
)
]
],
)
],
)
Expand Down

0 comments on commit 0d3bce2

Please sign in to comment.