From afd1311f3e6fed78b8e6cb97f1146869a363b81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 31 Oct 2024 11:34:44 +0100 Subject: [PATCH] otlpmetric: Add instrumentation scope attributes (#5935) Towards https://github.com/open-telemetry/opentelemetry-go/issues/5844 --- CHANGELOG.md | 2 ++ .../internal/transform/metricdata.go | 5 +++-- .../internal/transform/metricdata_test.go | 15 ++++++++++++--- .../internal/transform/metricdata.go | 5 +++-- .../internal/transform/metricdata_test.go | 15 ++++++++++++--- .../otlp/otlpmetric/transform/metricdata.go.tmpl | 5 +++-- .../otlpmetric/transform/metricdata_test.go.tmpl | 15 ++++++++++++--- 7 files changed, 47 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f098fd34a8..56a60b9a28d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add `Attributes attribute.Set` field to `ScopeRecords` in `go.opentelemetry.io/otel/log/logtest`. (#5927) - `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` adds instrumentation scope attributes. (#5934) - `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` adds instrumentation scope attributes. (#5934) +- `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` adds instrumentation scope attributes. (#5935) +- `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` adds instrumentation scope attributes. (#5935) ### Fixed diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go index e13dfdca505..abf7f021960 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata.go @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go index 1648fff2d78..d10b00257f9 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/metricdata_test.go @@ -805,9 +805,10 @@ var ( otelScopeMetrics = []metricdata.ScopeMetrics{ { Scope: instrumentation.Scope{ - Name: "test/code/path", - Version: "v0.1.0", - SchemaURL: semconv.SchemaURL, + Name: "test/code/path", + Version: "v0.1.0", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), }, Metrics: otelMetrics, }, @@ -818,6 +819,14 @@ var ( Scope: &cpb.InstrumentationScope{ Name: "test/code/path", Version: "v0.1.0", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, }, Metrics: pbMetrics, SchemaUrl: semconv.SchemaURL, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go index bede7e85171..8207b15a421 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata.go @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go index 1648fff2d78..d10b00257f9 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/metricdata_test.go @@ -805,9 +805,10 @@ var ( otelScopeMetrics = []metricdata.ScopeMetrics{ { Scope: instrumentation.Scope{ - Name: "test/code/path", - Version: "v0.1.0", - SchemaURL: semconv.SchemaURL, + Name: "test/code/path", + Version: "v0.1.0", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), }, Metrics: otelMetrics, }, @@ -818,6 +819,14 @@ var ( Scope: &cpb.InstrumentationScope{ Name: "test/code/path", Version: "v0.1.0", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, }, Metrics: pbMetrics, SchemaUrl: semconv.SchemaURL, diff --git a/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl b/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl index 313d08cd16c..d11ee433181 100644 --- a/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/metricdata.go.tmpl @@ -46,8 +46,9 @@ func ScopeMetrics(sms []metricdata.ScopeMetrics) ([]*mpb.ScopeMetrics, error) { out = append(out, &mpb.ScopeMetrics{ Scope: &cpb.InstrumentationScope{ - Name: sm.Scope.Name, - Version: sm.Scope.Version, + Name: sm.Scope.Name, + Version: sm.Scope.Version, + Attributes: AttrIter(sm.Scope.Attributes.Iter()), }, Metrics: ms, SchemaUrl: sm.Scope.SchemaURL, diff --git a/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl b/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl index 1648fff2d78..d10b00257f9 100644 --- a/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/metricdata_test.go.tmpl @@ -805,9 +805,10 @@ var ( otelScopeMetrics = []metricdata.ScopeMetrics{ { Scope: instrumentation.Scope{ - Name: "test/code/path", - Version: "v0.1.0", - SchemaURL: semconv.SchemaURL, + Name: "test/code/path", + Version: "v0.1.0", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), }, Metrics: otelMetrics, }, @@ -818,6 +819,14 @@ var ( Scope: &cpb.InstrumentationScope{ Name: "test/code/path", Version: "v0.1.0", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, }, Metrics: pbMetrics, SchemaUrl: semconv.SchemaURL,