diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1073c1e73..566829ae1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5929) - Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5929) - Performance improvements for attribute value `AsStringSlice`, `AsFloat64Slice`, `AsInt64Slice`, `AsBoolSlice`. (#6011) +- Change `EnabledParameters` to have a `Severity` field instead of a getter and setter in `go.opentelemetry.io/otel/log`. (#6009) ### Fixed diff --git a/log/DESIGN.md b/log/DESIGN.md index da1865191a1..568df49d96e 100644 --- a/log/DESIGN.md +++ b/log/DESIGN.md @@ -264,9 +264,9 @@ allocations and make it possible to handle new arguments, `Enabled` accepts a `EnabledParameters` struct, defined in [logger.go](logger.go), as the second method argument. -The `EnabledParameters` getters are returning values using the `(value, ok)` -idiom in order to indicate if the values were actually set by the caller or if -there are unspecified. +The `EnabledParameters` uses fields, instead of getters and setters, to allow +simpler usage which allows configuring the `EnabledParameters` in the same line +where `Enabled` is called. ### noop package diff --git a/log/logger.go b/log/logger.go index fe826819d8b..0773a49b608 100644 --- a/log/logger.go +++ b/log/logger.go @@ -138,18 +138,5 @@ func WithSchemaURL(schemaURL string) LoggerOption { // EnabledParameters represents payload for [Logger]'s Enabled method. type EnabledParameters struct { - severity Severity - severitySet bool -} - -// Severity returns the [Severity] level value, or [SeverityUndefined] if no value was set. -// The ok result indicates whether the value was set. -func (r *EnabledParameters) Severity() (value Severity, ok bool) { - return r.severity, r.severitySet -} - -// SetSeverity sets the [Severity] level. -func (r *EnabledParameters) SetSeverity(level Severity) { - r.severity = level - r.severitySet = true + Severity Severity } diff --git a/log/logtest/recorder_test.go b/log/logtest/recorder_test.go index 4efab499504..28d814528e2 100644 --- a/log/logtest/recorder_test.go +++ b/log/logtest/recorder_test.go @@ -68,21 +68,16 @@ func TestRecorderLoggerCreatesNewStruct(t *testing.T) { func TestLoggerEnabled(t *testing.T) { for _, tt := range []struct { - name string - options []Option - ctx context.Context - buildEnabledParameters func() log.EnabledParameters - - isEnabled bool + name string + options []Option + ctx context.Context + enabledParams log.EnabledParameters + want bool }{ { name: "the default option enables every log entry", ctx: context.Background(), - buildEnabledParameters: func() log.EnabledParameters { - return log.EnabledParameters{} - }, - - isEnabled: true, + want: true, }, { name: "with everything disabled", @@ -91,17 +86,13 @@ func TestLoggerEnabled(t *testing.T) { return false }), }, - ctx: context.Background(), - buildEnabledParameters: func() log.EnabledParameters { - return log.EnabledParameters{} - }, - - isEnabled: false, + ctx: context.Background(), + want: false, }, } { t.Run(tt.name, func(t *testing.T) { - e := NewRecorder(tt.options...).Logger("test").Enabled(tt.ctx, tt.buildEnabledParameters()) - assert.Equal(t, tt.isEnabled, e) + e := NewRecorder(tt.options...).Logger("test").Enabled(tt.ctx, tt.enabledParams) + assert.Equal(t, tt.want, e) }) } } diff --git a/sdk/log/logger_test.go b/sdk/log/logger_test.go index 0c2f793db97..b8da0750bad 100644 --- a/sdk/log/logger_test.go +++ b/sdk/log/logger_test.go @@ -280,10 +280,9 @@ func BenchmarkLoggerEnabled(b *testing.B) { WithProcessor(newFltrProcessor("0", false)), WithProcessor(newFltrProcessor("1", true)), ) - logger := provider.Logger("BenchmarkLoggerEnabled") - ctx, param := context.Background(), log.EnabledParameters{} - param.SetSeverity(log.SeverityDebug) - + logger := provider.Logger(b.Name()) + ctx := context.Background() + param := log.EnabledParameters{Severity: log.SeverityDebug} var enabled bool b.ReportAllocs()