Skip to content

Commit

Permalink
log: Rename EnabledParameters to EnabledParams
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared committed Nov 29, 2024
1 parent 51dca45 commit f8b0b2b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion log/internal/global/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions log/internal/global/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions log/logtest/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions log/logtest/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,29 @@ 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,
},
{
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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion log/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 2 additions & 2 deletions sdk/log/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/log/internal/x/x.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions sdk/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sdk/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
})
}
}
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sdk/log/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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{})
}

0 comments on commit f8b0b2b

Please sign in to comment.