From f4cd2e086e2851cce37fa5385b777e17367adf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 30 Oct 2024 13:46:33 +0100 Subject: [PATCH 1/3] otlplog: Add instrumentation scope attributes --- CHANGELOG.md | 2 ++ .../otlp/otlplog/otlploggrpc/internal/transform/log.go | 5 +++-- .../otlplog/otlploggrpc/internal/transform/log_test.go | 8 ++++++++ .../otlp/otlplog/otlploghttp/internal/transform/log.go | 5 +++-- .../otlplog/otlploghttp/internal/transform/log_test.go | 8 ++++++++ internal/shared/otlp/otlplog/transform/log.go.tmpl | 3 ++- internal/shared/otlp/otlplog/transform/log_test.go.tmpl | 8 ++++++++ 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eab1919f403..46f3e466bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm The package contains semantic conventions from the `v1.27.0` version of the OpenTelemetry Semantic Conventions. (#5894) - Add `Attributes attribute.Set` field to `Scope` in `go.opentelemetry.io/otel/sdk/instrumentation`. (#5903) - Add `Attributes attribute.Set` field to `ScopeRecords` in `go.opentelemetry.io/otel/log/logtest`. (#5927) +- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` adds instrumentation scope attributes. (#5933) +- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` adds instrumentation scope attributes. (#5933) ### Fixed diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go index b03f3fb54ac..03e9d8c71cd 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go @@ -50,8 +50,9 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, - Version: scope.Version, + Name: scope.Name, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go index c4623ea29b9..0f5325459e8 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go @@ -84,6 +84,14 @@ var ( pbScope = &cpb.InstrumentationScope{ Name: "otel/test/code/path1", Version: "v0.1.1", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, } pbScope2 = &cpb.InstrumentationScope{ Name: "otel/test/code/path2", diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go index 1ab95f93948..4b52a14ebc6 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go @@ -50,8 +50,9 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, - Version: scope.Version, + Name: scope.Name, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go index c4623ea29b9..0f5325459e8 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go @@ -84,6 +84,14 @@ var ( pbScope = &cpb.InstrumentationScope{ Name: "otel/test/code/path1", Version: "v0.1.1", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, } pbScope2 = &cpb.InstrumentationScope{ Name: "otel/test/code/path2", diff --git a/internal/shared/otlp/otlplog/transform/log.go.tmpl b/internal/shared/otlp/otlplog/transform/log.go.tmpl index 1ab95f93948..f396be88abf 100644 --- a/internal/shared/otlp/otlplog/transform/log.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log.go.tmpl @@ -51,7 +51,8 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ Name: scope.Name, - Version: scope.Version, + Version: scope.Version, + Attributes: AttrIter(scope.Attributes.Iter()), } sl.SchemaUrl = scope.SchemaURL } diff --git a/internal/shared/otlp/otlplog/transform/log_test.go.tmpl b/internal/shared/otlp/otlplog/transform/log_test.go.tmpl index c4623ea29b9..0f5325459e8 100644 --- a/internal/shared/otlp/otlplog/transform/log_test.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log_test.go.tmpl @@ -84,6 +84,14 @@ var ( pbScope = &cpb.InstrumentationScope{ Name: "otel/test/code/path1", Version: "v0.1.1", + Attributes: []*cpb.KeyValue{ + { + Key: "foo", + Value: &cpb.AnyValue{ + Value: &cpb.AnyValue_StringValue{StringValue: "bar"}, + }, + }, + }, } pbScope2 = &cpb.InstrumentationScope{ Name: "otel/test/code/path2", From 5dbefcf474a6c3f1a1347dd000a7ff0c7b3749ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 30 Oct 2024 14:02:24 +0100 Subject: [PATCH 2/3] Fix test --- .../otlp/otlplog/otlploggrpc/internal/transform/log.go | 2 +- .../otlplog/otlploggrpc/internal/transform/log_test.go | 8 +++++--- .../otlp/otlplog/otlploghttp/internal/transform/log.go | 2 +- .../otlplog/otlploghttp/internal/transform/log_test.go | 8 +++++--- internal/shared/otlp/otlplog/transform/log_test.go.tmpl | 8 +++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go index 03e9d8c71cd..ff8bab8696f 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go @@ -50,7 +50,7 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, + Name: scope.Name, Version: scope.Version, Attributes: AttrIter(scope.Attributes.Iter()), } diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go index 0f5325459e8..ead467814ef 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log_test.go @@ -16,6 +16,7 @@ import ( lpb "go.opentelemetry.io/proto/otlp/logs/v1" rpb "go.opentelemetry.io/proto/otlp/resource/v1" + "go.opentelemetry.io/otel/attribute" api "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/log" @@ -70,9 +71,10 @@ var ( flagsD = byte(0) scope = instrumentation.Scope{ - Name: "otel/test/code/path1", - Version: "v0.1.1", - SchemaURL: semconv.SchemaURL, + Name: "otel/test/code/path1", + Version: "v0.1.1", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), } scope2 = instrumentation.Scope{ Name: "otel/test/code/path2", diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go index 4b52a14ebc6..f396be88abf 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go @@ -50,7 +50,7 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, + Name: scope.Name, Version: scope.Version, Attributes: AttrIter(scope.Attributes.Iter()), } diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go index 0f5325459e8..ead467814ef 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log_test.go @@ -16,6 +16,7 @@ import ( lpb "go.opentelemetry.io/proto/otlp/logs/v1" rpb "go.opentelemetry.io/proto/otlp/resource/v1" + "go.opentelemetry.io/otel/attribute" api "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/log" @@ -70,9 +71,10 @@ var ( flagsD = byte(0) scope = instrumentation.Scope{ - Name: "otel/test/code/path1", - Version: "v0.1.1", - SchemaURL: semconv.SchemaURL, + Name: "otel/test/code/path1", + Version: "v0.1.1", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), } scope2 = instrumentation.Scope{ Name: "otel/test/code/path2", diff --git a/internal/shared/otlp/otlplog/transform/log_test.go.tmpl b/internal/shared/otlp/otlplog/transform/log_test.go.tmpl index 0f5325459e8..ead467814ef 100644 --- a/internal/shared/otlp/otlplog/transform/log_test.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log_test.go.tmpl @@ -16,6 +16,7 @@ import ( lpb "go.opentelemetry.io/proto/otlp/logs/v1" rpb "go.opentelemetry.io/proto/otlp/resource/v1" + "go.opentelemetry.io/otel/attribute" api "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/log" @@ -70,9 +71,10 @@ var ( flagsD = byte(0) scope = instrumentation.Scope{ - Name: "otel/test/code/path1", - Version: "v0.1.1", - SchemaURL: semconv.SchemaURL, + Name: "otel/test/code/path1", + Version: "v0.1.1", + SchemaURL: semconv.SchemaURL, + Attributes: attribute.NewSet(attribute.String("foo", "bar")), } scope2 = instrumentation.Scope{ Name: "otel/test/code/path2", From ce7854b71813b4f6c4e7f2c9853731f6d264bb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 30 Oct 2024 14:04:25 +0100 Subject: [PATCH 3/3] fmt --- exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go | 2 +- exporters/otlp/otlplog/otlploghttp/internal/transform/log.go | 2 +- internal/shared/otlp/otlplog/transform/log.go.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go index ff8bab8696f..03e9d8c71cd 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/transform/log.go @@ -50,7 +50,7 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, + Name: scope.Name, Version: scope.Version, Attributes: AttrIter(scope.Attributes.Iter()), } diff --git a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go index f396be88abf..4b52a14ebc6 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/transform/log.go @@ -50,7 +50,7 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, + Name: scope.Name, Version: scope.Version, Attributes: AttrIter(scope.Attributes.Iter()), } diff --git a/internal/shared/otlp/otlplog/transform/log.go.tmpl b/internal/shared/otlp/otlplog/transform/log.go.tmpl index f396be88abf..4b52a14ebc6 100644 --- a/internal/shared/otlp/otlplog/transform/log.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log.go.tmpl @@ -50,7 +50,7 @@ func ResourceLogs(records []log.Record) []*lpb.ResourceLogs { var emptyScope instrumentation.Scope if scope != emptyScope { sl.Scope = &cpb.InstrumentationScope{ - Name: scope.Name, + Name: scope.Name, Version: scope.Version, Attributes: AttrIter(scope.Attributes.Iter()), }