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
  • Loading branch information
ocelotl committed Nov 25, 2020
1 parent da7597c commit d9cec44
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 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,20 @@ def _translate_data(
)
)

instrumentation_library_metrics.instrumentation_library.name = (
export_record.instrument.meter.instrumentation_info.name
)

version = (
export_record.instrument.meter.instrumentation_info.version
)

if version:
(
instrumentation_library_metrics.
instrumentation_library.version
) = 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 @@ -14,7 +14,6 @@
"""OTLP Span Exporter"""

import logging
import os
from typing import Optional, Sequence

from grpc import ChannelCredentials
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 d9cec44

Please sign in to comment.