From c3cb44d63a906ae9137db1e36aaac1a71be55508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 29 Oct 2024 15:05:21 +0100 Subject: [PATCH 1/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf75a3cdcb..bf682c8b02e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5892) - `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5911) - `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915) +- Support scope attributes and make them as identifying for `Logger` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/log`. (#5925) From 3bc3977b633d8cd32aefc31d3fd32d60968c190e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 29 Oct 2024 15:06:37 +0100 Subject: [PATCH 2/5] Failing test --- sdk/log/provider_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index fecd8f10127..133e752896b 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -302,7 +302,7 @@ func TestLoggerProviderLogger(t *testing.T) { l0, l1, l2 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) assert.NotSame(t, l0, l1) - assert.Same(t, l0, l2) // TODO (#3368): Change to assert.NotSame. + assert.NotSame(t, l0, l2) assert.NotSame(t, l1, l2) l3, l4, l5 := p.Logger("l0"), p.Logger("l1"), p.Logger("l0", log.WithInstrumentationAttributes(attribute.String("foo", "bar"))) From 825e207157014865b911cd49e12d8c971e9c5e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 29 Oct 2024 15:07:26 +0100 Subject: [PATCH 3/5] Implement LoggerProvider.Logger --- sdk/log/provider.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/log/provider.go b/sdk/log/provider.go index 14084ed99a8..8c825e6ab79 100644 --- a/sdk/log/provider.go +++ b/sdk/log/provider.go @@ -124,9 +124,10 @@ func (p *LoggerProvider) Logger(name string, opts ...log.LoggerOption) log.Logge cfg := log.NewLoggerConfig(opts...) scope := instrumentation.Scope{ - Name: name, - Version: cfg.InstrumentationVersion(), - SchemaURL: cfg.SchemaURL(), + Name: name, + Version: cfg.InstrumentationVersion(), + SchemaURL: cfg.SchemaURL(), + Attributes: cfg.InstrumentationAttributes(), } p.loggersMu.Lock() From c211048b12acbf0ef8b25166bd0be252e57a773e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 29 Oct 2024 15:08:09 +0100 Subject: [PATCH 4/5] Failing TestDelegation --- log/internal/global/log_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/log/internal/global/log_test.go b/log/internal/global/log_test.go index a27f832113d..ae2c5b2a6dd 100644 --- a/log/internal/global/log_test.go +++ b/log/internal/global/log_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/log/embedded" "go.opentelemetry.io/otel/log/noop" @@ -128,6 +129,9 @@ func TestDelegation(t *testing.T) { alt := provider.Logger("alt") assert.NotSame(t, pre0, alt) + alt2 := provider.Logger(preName, log.WithInstrumentationAttributes(attribute.String("k", "v"))) + assert.NotSame(t, pre0, alt2) + delegate := &testLoggerProvider{} provider.setDelegate(delegate) From 4921d872f6ee3bd90b733263939a0401dd4a8d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 29 Oct 2024 15:09:29 +0100 Subject: [PATCH 5/5] Implement global loggerProvider.Logger --- log/internal/global/log.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/log/internal/global/log.go b/log/internal/global/log.go index 8a27358d4ba..d97ee966350 100644 --- a/log/internal/global/log.go +++ b/log/internal/global/log.go @@ -8,6 +8,7 @@ import ( "sync" "sync/atomic" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/log/embedded" ) @@ -15,7 +16,12 @@ import ( // instLib defines the instrumentation library a logger is created for. // // Do not use sdk/instrumentation (API cannot depend on the SDK). -type instLib struct{ name, version, schemaURL string } +type instLib struct { + name string + version string + schemaURL string + attrs attribute.Set +} type loggerProvider struct { embedded.LoggerProvider @@ -41,6 +47,7 @@ func (p *loggerProvider) Logger(name string, options ...log.LoggerOption) log.Lo name: name, version: cfg.InstrumentationVersion(), schemaURL: cfg.SchemaURL(), + attrs: cfg.InstrumentationAttributes(), } if p.loggers == nil {