diff --git a/log/internal/global/log.go b/log/internal/global/log.go index d97ee966350..dd593c289ee 100644 --- a/log/internal/global/log.go +++ b/log/internal/global/log.go @@ -94,7 +94,7 @@ func (l *logger) Emit(ctx context.Context, r log.Record) { } } -func (l *logger) Enabled(ctx context.Context, param log.EnabledParameters) bool { +func (l *logger) Enabled(ctx context.Context, param log.EnabledParams) bool { var enabled bool if del, ok := l.delegate.Load().(log.Logger); ok { enabled = del.Enabled(ctx, param) diff --git a/log/internal/global/log_test.go b/log/internal/global/log_test.go index ae2c5b2a6dd..9b7fb3b5981 100644 --- a/log/internal/global/log_test.go +++ b/log/internal/global/log_test.go @@ -52,7 +52,7 @@ func TestLoggerConcurrentSafe(t *testing.T) { ctx := context.Background() var r log.Record - var param log.EnabledParameters + var param log.EnabledParams var enabled bool for { @@ -105,14 +105,14 @@ type testLogger struct { } func (l *testLogger) Emit(context.Context, log.Record) { l.emitN++ } -func (l *testLogger) Enabled(context.Context, log.EnabledParameters) bool { +func (l *testLogger) Enabled(context.Context, log.EnabledParams) bool { l.enabledN++ return true } func emitRecord(l log.Logger) { ctx := context.Background() - var param log.EnabledParameters + var param log.EnabledParams var r log.Record _ = l.Enabled(ctx, param) diff --git a/log/logger.go b/log/logger.go index 0773a49b608..83fa3f3a16e 100644 --- a/log/logger.go +++ b/log/logger.go @@ -56,7 +56,7 @@ type Logger interface { // // Notice: Enabled is intended to be used by log bridges. // Is should not be used for writing instrumentation. - Enabled(ctx context.Context, param EnabledParameters) bool + Enabled(ctx context.Context, param EnabledParams) bool } // LoggerOption applies configuration options to a [Logger]. @@ -136,7 +136,7 @@ func WithSchemaURL(schemaURL string) LoggerOption { }) } -// EnabledParameters represents payload for [Logger]'s Enabled method. -type EnabledParameters struct { +// EnabledParams represents payload for [Logger]'s Enabled method. +type EnabledParams struct { Severity Severity } diff --git a/log/logtest/recorder.go b/log/logtest/recorder.go index fd986c9afc4..af7c55af77e 100644 --- a/log/logtest/recorder.go +++ b/log/logtest/recorder.go @@ -12,9 +12,9 @@ import ( "go.opentelemetry.io/otel/log/embedded" ) -type enabledFn func(context.Context, log.EnabledParameters) bool +type enabledFn func(context.Context, log.EnabledParams) bool -var defaultEnabledFunc = func(context.Context, log.EnabledParameters) bool { +var defaultEnabledFunc = func(context.Context, log.EnabledParams) bool { return true } @@ -43,7 +43,7 @@ func (f optFunc) apply(c config) config { return f(c) } // WithEnabledFunc allows configuring whether the [Recorder] is enabled for specific log entries or not. // // By default, the Recorder is enabled for every log entry. -func WithEnabledFunc(fn func(context.Context, log.EnabledParameters) bool) Option { +func WithEnabledFunc(fn func(context.Context, log.EnabledParams) bool) Option { return optFunc(func(c config) config { c.enabledFn = fn return c @@ -159,7 +159,7 @@ type logger struct { } // Enabled indicates whether a specific record should be stored. -func (l *logger) Enabled(ctx context.Context, opts log.EnabledParameters) bool { +func (l *logger) Enabled(ctx context.Context, opts log.EnabledParams) bool { if l.enabledFn == nil { return defaultEnabledFunc(ctx, opts) } diff --git a/log/logtest/recorder_test.go b/log/logtest/recorder_test.go index 4efab499504..22cfbfbb6c5 100644 --- a/log/logtest/recorder_test.go +++ b/log/logtest/recorder_test.go @@ -71,15 +71,15 @@ func TestLoggerEnabled(t *testing.T) { name string options []Option ctx context.Context - buildEnabledParameters func() log.EnabledParameters + buildEnabledParameters func() log.EnabledParams isEnabled bool }{ { name: "the default option enables every log entry", ctx: context.Background(), - buildEnabledParameters: func() log.EnabledParameters { - return log.EnabledParameters{} + buildEnabledParameters: func() log.EnabledParams { + return log.EnabledParams{} }, isEnabled: true, @@ -87,13 +87,13 @@ func TestLoggerEnabled(t *testing.T) { { name: "with everything disabled", options: []Option{ - WithEnabledFunc(func(context.Context, log.EnabledParameters) bool { + WithEnabledFunc(func(context.Context, log.EnabledParams) bool { return false }), }, ctx: context.Background(), - buildEnabledParameters: func() log.EnabledParameters { - return log.EnabledParameters{} + buildEnabledParameters: func() log.EnabledParams { + return log.EnabledParams{} }, isEnabled: false, @@ -108,7 +108,7 @@ func TestLoggerEnabled(t *testing.T) { func TestLoggerEnabledFnUnset(t *testing.T) { r := &logger{} - assert.True(t, r.Enabled(context.Background(), log.EnabledParameters{})) + assert.True(t, r.Enabled(context.Background(), log.EnabledParams{})) } func TestRecorderEmitAndReset(t *testing.T) { @@ -161,7 +161,7 @@ func TestRecorderConcurrentSafe(t *testing.T) { defer wg.Done() nr := r.Logger("test") - nr.Enabled(context.Background(), log.EnabledParameters{}) + nr.Enabled(context.Background(), log.EnabledParams{}) nr.Emit(context.Background(), log.Record{}) r.Result() diff --git a/log/noop/noop.go b/log/noop/noop.go index f45a7c7e0b3..d1e792e517e 100644 --- a/log/noop/noop.go +++ b/log/noop/noop.go @@ -47,4 +47,4 @@ type Logger struct{ embedded.Logger } func (Logger) Emit(context.Context, log.Record) {} // Enabled returns false. No log records are ever emitted. -func (Logger) Enabled(context.Context, log.EnabledParameters) bool { return false } +func (Logger) Enabled(context.Context, log.EnabledParams) bool { return false } diff --git a/sdk/log/example_test.go b/sdk/log/example_test.go index 8070beef771..2b3bb2c3b34 100644 --- a/sdk/log/example_test.go +++ b/sdk/log/example_test.go @@ -90,7 +90,7 @@ type ContextFilterProcessor struct { } type filter interface { - Enabled(ctx context.Context, param logapi.EnabledParameters) bool + Enabled(ctx context.Context, param logapi.EnabledParams) bool } func (p *ContextFilterProcessor) OnEmit(ctx context.Context, record *log.Record) error { @@ -100,7 +100,7 @@ func (p *ContextFilterProcessor) OnEmit(ctx context.Context, record *log.Record) return p.Processor.OnEmit(ctx, record) } -func (p *ContextFilterProcessor) Enabled(ctx context.Context, param logapi.EnabledParameters) bool { +func (p *ContextFilterProcessor) Enabled(ctx context.Context, param logapi.EnabledParams) bool { p.lazyFilter.Do(func() { if f, ok := p.Processor.(filter); ok { p.filter = f diff --git a/sdk/log/internal/x/x.go b/sdk/log/internal/x/x.go index ca78d109778..3a876e1369f 100644 --- a/sdk/log/internal/x/x.go +++ b/sdk/log/internal/x/x.go @@ -43,5 +43,5 @@ type FilterProcessor interface { // indeterminate state. // // Implementations should not modify the param. - Enabled(ctx context.Context, param log.EnabledParameters) bool + Enabled(ctx context.Context, param log.EnabledParams) bool } diff --git a/sdk/log/logger.go b/sdk/log/logger.go index d6ca2ea41aa..43c65d06922 100644 --- a/sdk/log/logger.go +++ b/sdk/log/logger.go @@ -49,7 +49,7 @@ func (l *logger) Emit(ctx context.Context, r log.Record) { // If it is not possible to definitively determine the param will be // processed, true will be returned by default. A value of false will only be // returned if it can be positively verified that no Processor will process. -func (l *logger) Enabled(ctx context.Context, param log.EnabledParameters) bool { +func (l *logger) Enabled(ctx context.Context, param log.EnabledParams) bool { fltrs := l.provider.filterProcessors() // If there are more Processors than FilterProcessors we cannot be sure // that all Processors will drop the record. Therefore, return true. @@ -58,7 +58,7 @@ func (l *logger) Enabled(ctx context.Context, param log.EnabledParameters) bool return len(l.provider.processors) > len(fltrs) || anyEnabled(ctx, param, fltrs) } -func anyEnabled(ctx context.Context, param log.EnabledParameters, fltrs []x.FilterProcessor) bool { +func anyEnabled(ctx context.Context, param log.EnabledParams, fltrs []x.FilterProcessor) bool { for _, f := range fltrs { if f.Enabled(ctx, param) { // At least one Processor will process the Record. diff --git a/sdk/log/logger_test.go b/sdk/log/logger_test.go index b8da0750bad..27bcfc3fe41 100644 --- a/sdk/log/logger_test.go +++ b/sdk/log/logger_test.go @@ -270,7 +270,7 @@ func TestLoggerEnabled(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - assert.Equal(t, tc.expected, tc.logger.Enabled(tc.ctx, log.EnabledParameters{})) + assert.Equal(t, tc.expected, tc.logger.Enabled(tc.ctx, log.EnabledParams{})) }) } } @@ -282,7 +282,7 @@ func BenchmarkLoggerEnabled(b *testing.B) { ) logger := provider.Logger(b.Name()) ctx := context.Background() - param := log.EnabledParameters{Severity: log.SeverityDebug} + param := log.EnabledParams{Severity: log.SeverityDebug} var enabled bool b.ReportAllocs() diff --git a/sdk/log/provider_test.go b/sdk/log/provider_test.go index 133e752896b..5dfcc488795 100644 --- a/sdk/log/provider_test.go +++ b/sdk/log/provider_test.go @@ -76,7 +76,7 @@ func newFltrProcessor(name string, enabled bool) *fltrProcessor { } } -func (p *fltrProcessor) Enabled(context.Context, log.EnabledParameters) bool { +func (p *fltrProcessor) Enabled(context.Context, log.EnabledParams) bool { return p.enabled } @@ -388,5 +388,5 @@ func BenchmarkLoggerProviderLogger(b *testing.B) { } b.StopTimer() - loggers[0].Enabled(context.Background(), log.EnabledParameters{}) + loggers[0].Enabled(context.Background(), log.EnabledParams{}) }