From 4f94b1e661e719c758c5700c5ba5f4e418db980e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 30 Oct 2024 06:40:14 +0100 Subject: [PATCH] log/logtest: Add Attributes to ScopeRecords (#5927) Towards https://github.com/open-telemetry/opentelemetry-go/issues/3368 --- CHANGELOG.md | 1 + log/logtest/recorder.go | 10 +++++++--- log/logtest/recorder_test.go | 9 ++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9720ef72484..eab1919f403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `go.opentelemetry.io/otel/semconv/v1.27.0` package. 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) ### Fixed diff --git a/log/logtest/recorder.go b/log/logtest/recorder.go index 84449b14377..fd986c9afc4 100644 --- a/log/logtest/recorder.go +++ b/log/logtest/recorder.go @@ -7,6 +7,7 @@ import ( "context" "sync" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/log/embedded" ) @@ -66,6 +67,8 @@ type ScopeRecords struct { Version string // SchemaURL of the telemetry emitted by the scope. SchemaURL string + // Attributes of the telemetry emitted by the scope. + Attributes attribute.Set // Records are the log records, and their associated context this // instrumentation scope recorded. @@ -104,9 +107,10 @@ func (r *Recorder) Logger(name string, opts ...log.LoggerOption) log.Logger { nl := &logger{ scopeRecord: &ScopeRecords{ - Name: name, - Version: cfg.InstrumentationVersion(), - SchemaURL: cfg.SchemaURL(), + Name: name, + Version: cfg.InstrumentationVersion(), + SchemaURL: cfg.SchemaURL(), + Attributes: cfg.InstrumentationAttributes(), }, enabledFn: r.enabledFn, } diff --git a/log/logtest/recorder_test.go b/log/logtest/recorder_test.go index 4ab3c4eedf9..4efab499504 100644 --- a/log/logtest/recorder_test.go +++ b/log/logtest/recorder_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/log" ) @@ -37,13 +38,15 @@ func TestRecorderLogger(t *testing.T) { loggerOptions: []log.LoggerOption{ log.WithInstrumentationVersion("logtest v42"), log.WithSchemaURL("https://example.com"), + log.WithInstrumentationAttributes(attribute.String("foo", "bar")), }, wantLogger: &logger{ scopeRecord: &ScopeRecords{ - Name: "test", - Version: "logtest v42", - SchemaURL: "https://example.com", + Name: "test", + Version: "logtest v42", + SchemaURL: "https://example.com", + Attributes: attribute.NewSet(attribute.String("foo", "bar")), }, }, },