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 d48c672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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 d48c672

Please sign in to comment.