From 2a50fab505a4cb2518521f073f3415bf7d2f0a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 31 Oct 2024 12:28:11 +0100 Subject: [PATCH] otlplog: Add instrumentation scope attributes (#5933) Towards https://github.com/open-telemetry/opentelemetry-go/issues/5844 --- CHANGELOG.md | 2 ++ .../otlploggrpc/internal/transform/log.go | 5 +++-- .../otlploggrpc/internal/transform/log_test.go | 16 +++++++++++++--- .../otlploghttp/internal/transform/log.go | 5 +++-- .../otlploghttp/internal/transform/log_test.go | 16 +++++++++++++--- .../shared/otlp/otlplog/transform/log.go.tmpl | 5 +++-- .../otlp/otlplog/transform/log_test.go.tmpl | 16 +++++++++++++--- 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a60b9a28d..b4f90763a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - `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) +- `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..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", @@ -84,6 +86,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..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", @@ -84,6 +86,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..4b52a14ebc6 100644 --- a/internal/shared/otlp/otlplog/transform/log.go.tmpl +++ b/internal/shared/otlp/otlplog/transform/log.go.tmpl @@ -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/internal/shared/otlp/otlplog/transform/log_test.go.tmpl b/internal/shared/otlp/otlplog/transform/log_test.go.tmpl index c4623ea29b9..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", @@ -84,6 +86,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",