Skip to content

Commit

Permalink
Bump otel/log after introducing EnabledParameters (#6115)
Browse files Browse the repository at this point in the history
Follows open-telemetry/opentelemetry-go#5791
which introduces a breaking change for the updated Go modules.
  • Loading branch information
pellared authored Sep 17, 2024
1 parent a69cb51 commit 1bd570f
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bridges/otellogr/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/go-logr/logr v1.4.2
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.6.0
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985
)

require (
Expand Down
4 changes: 2 additions & 2 deletions bridges/otellogr/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985 h1:dD3nAsIm6kjeVCS4y3Xt2yTbauFvVGU3xcUOdfpd7bA=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
Expand Down
2 changes: 1 addition & 1 deletion bridges/otellogrus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.6.0
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985
)

require (
Expand Down
4 changes: 2 additions & 2 deletions bridges/otellogrus/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985 h1:dD3nAsIm6kjeVCS4y3Xt2yTbauFvVGU3xcUOdfpd7bA=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
Expand Down
2 changes: 1 addition & 1 deletion bridges/otelslog/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.6.0
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985
)

require (
Expand Down
4 changes: 2 additions & 2 deletions bridges/otelslog/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985 h1:dD3nAsIm6kjeVCS4y3Xt2yTbauFvVGU3xcUOdfpd7bA=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
Expand Down
6 changes: 3 additions & 3 deletions bridges/otelslog/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ func (h *Handler) convertRecord(r slog.Record) log.Record {
// Enable returns true if the Handler is enabled to log for the provided
// context and Level. Otherwise, false is returned if it is not enabled.
func (h *Handler) Enabled(ctx context.Context, l slog.Level) bool {
var record log.Record
var param log.EnabledParameters
const sevOffset = slog.Level(log.SeverityDebug) - slog.LevelDebug
record.SetSeverity(log.Severity(l + sevOffset))
return h.logger.Enabled(ctx, record)
param.SetSeverity(log.Severity(l + sevOffset))
return h.logger.Enabled(ctx, param)
}

// WithAttrs returns a new [slog.Handler] based on h that will log using the
Expand Down
8 changes: 6 additions & 2 deletions bridges/otelslog/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ type enablerKey uint

var enableKey enablerKey

func (r *recorder) Enabled(ctx context.Context, record log.Record) bool {
return ctx.Value(enableKey) != nil || record.Severity() >= r.MinSeverity
func (r *recorder) Enabled(ctx context.Context, param log.EnabledParameters) bool {
lvl, ok := param.Severity()
if !ok {
return true
}
return ctx.Value(enableKey) != nil || lvl >= r.MinSeverity
}

func (r *recorder) Emit(_ context.Context, record log.Record) {
Expand Down
12 changes: 6 additions & 6 deletions bridges/otelzap/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func NewCore(name string, opts ...Option) *Core {

// Enabled decides whether a given logging level is enabled when logging a message.
func (o *Core) Enabled(level zapcore.Level) bool {
r := log.Record{}
r.SetSeverity(convertLevel(level))
return o.logger.Enabled(context.Background(), r)
param := log.EnabledParameters{}
param.SetSeverity(convertLevel(level))
return o.logger.Enabled(context.Background(), param)
}

// With adds structured context to the Core.
Expand Down Expand Up @@ -176,15 +176,15 @@ func (o *Core) Sync() error {
// Check determines whether the supplied Entry should be logged.
// If the entry should be logged, the Core adds itself to the CheckedEntry and returns the result.
func (o *Core) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
r := log.Record{}
r.SetSeverity(convertLevel(ent.Level))
param := log.EnabledParameters{}
param.SetSeverity(convertLevel(ent.Level))

logger := o.logger
if ent.LoggerName != "" {
logger = o.provider.Logger(ent.LoggerName, o.opts...)
}

if logger.Enabled(context.Background(), r) {
if logger.Enabled(context.Background(), param) {
return ce.AddCore(ent, o)
}
return ce
Expand Down
8 changes: 6 additions & 2 deletions bridges/otelzap/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ func TestCore(t *testing.T) {
}

func TestCoreEnabled(t *testing.T) {
enabledFunc := func(c context.Context, r log.Record) bool {
return r.Severity() >= log.SeverityInfo
enabledFunc := func(c context.Context, param log.EnabledParameters) bool {
lvl, ok := param.Severity()
if !ok {
return true
}
return lvl >= log.SeverityInfo
}

r := logtest.NewRecorder(logtest.WithEnabledFunc(enabledFunc))
Expand Down
2 changes: 1 addition & 1 deletion bridges/otelzap/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.6.0
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985
go.uber.org/zap v1.27.0
)

Expand Down
4 changes: 2 additions & 2 deletions bridges/otelzap/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985 h1:dD3nAsIm6kjeVCS4y3Xt2yTbauFvVGU3xcUOdfpd7bA=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
Expand Down
4 changes: 2 additions & 2 deletions processors/minsev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.22

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel/log v0.6.0
go.opentelemetry.io/otel/sdk/log v0.6.0
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985
go.opentelemetry.io/otel/sdk/log v0.6.1-0.20240916071759-a7e83aace985
)

require (
Expand Down
8 changes: 4 additions & 4 deletions processors/minsev/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/log v0.6.0 h1:nH66tr+dmEgW5y+F9LanGJUBYPrRgP4g2EkmPE3LeK8=
go.opentelemetry.io/otel/log v0.6.0/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985 h1:dD3nAsIm6kjeVCS4y3Xt2yTbauFvVGU3xcUOdfpd7bA=
go.opentelemetry.io/otel/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:KdySypjQHhP069JX0z/t26VHwa8vSwzgaKmXtIB3fJM=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/sdk v1.30.0 h1:cHdik6irO49R5IysVhdn8oaiR9m8XluDaJAs4DfOrYE=
go.opentelemetry.io/otel/sdk v1.30.0/go.mod h1:p14X4Ok8S+sygzblytT1nqG98QG2KYKv++HE0LY/mhg=
go.opentelemetry.io/otel/sdk/log v0.6.0 h1:4J8BwXY4EeDE9Mowg+CyhWVBhTSLXVXodiXxS/+PGqI=
go.opentelemetry.io/otel/sdk/log v0.6.0/go.mod h1:L1DN8RMAduKkrwRAFDEX3E3TLOq46+XMGSbUfHU/+vE=
go.opentelemetry.io/otel/sdk/log v0.6.1-0.20240916071759-a7e83aace985 h1:fzvEpgpuicrPQ0ThuRkvovPkcjaXfvkf+1bcW0XO49U=
go.opentelemetry.io/otel/sdk/log v0.6.1-0.20240916071759-a7e83aace985/go.mod h1:L1DN8RMAduKkrwRAFDEX3E3TLOq46+XMGSbUfHU/+vE=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
Expand Down
23 changes: 14 additions & 9 deletions processors/minsev/minsev.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewLogProcessor(downstream log.Processor, minimum api.Severity) *LogProcess
// filterProcessor is the experimental optional interface a Processor can
// implement (go.opentelemetry.io/otel/sdk/log/internal/x).
type filterProcessor interface {
Enabled(ctx context.Context, record log.Record) bool
Enabled(ctx context.Context, param api.EnabledParameters) bool
}

// LogProcessor is an [log.Processor] implementation that wraps another
Expand Down Expand Up @@ -63,20 +63,25 @@ func (p *LogProcessor) OnEmit(ctx context.Context, record *log.Record) error {
}

// Enabled returns if the [log.Processor] that p wraps is enabled if the
// severity of record is greater than or equal to p.Minimum. Otherwise false is
// severity of param is greater than or equal to p.Minimum. Otherwise false is
// returned.
func (p *LogProcessor) Enabled(ctx context.Context, record log.Record) bool {
func (p *LogProcessor) Enabled(ctx context.Context, param api.EnabledParameters) bool {
lvl, ok := param.Severity()
if !ok {
return true
}

if p.filter != nil {
return record.Severity() >= p.Minimum && p.filter.Enabled(ctx, record)
return lvl >= p.Minimum && p.filter.Enabled(ctx, param)
}
return record.Severity() >= p.Minimum
return lvl >= p.Minimum
}

var defaultProcessor = noopProcessor{}

type noopProcessor struct{}

func (p noopProcessor) OnEmit(context.Context, *log.Record) error { return nil }
func (p noopProcessor) Enabled(context.Context, log.Record) bool { return false }
func (p noopProcessor) Shutdown(context.Context) error { return nil }
func (p noopProcessor) ForceFlush(context.Context) error { return nil }
func (p noopProcessor) OnEmit(context.Context, *log.Record) error { return nil }
func (p noopProcessor) Enabled(context.Context, api.EnabledParameters) bool { return false }
func (p noopProcessor) Shutdown(context.Context) error { return nil }
func (p noopProcessor) ForceFlush(context.Context) error { return nil }
39 changes: 24 additions & 15 deletions processors/minsev/minsev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,32 @@ var severities = []api.Severity{
api.SeverityFatal, api.SeverityFatal1, api.SeverityFatal2, api.SeverityFatal3, api.SeverityFatal4,
}

type args struct {
type emitArgs struct {
Ctx context.Context
Record *log.Record
}

type enabledArgs struct {
Ctx context.Context
Param api.EnabledParameters
}

type processor struct {
ReturnErr error

OnEmitCalls []args
EnabledCalls []args
OnEmitCalls []emitArgs
EnabledCalls []enabledArgs
ForceFlushCalls []context.Context
ShutdownCalls []context.Context
}

func (p *processor) OnEmit(ctx context.Context, r *log.Record) error {
p.OnEmitCalls = append(p.OnEmitCalls, args{ctx, r})
p.OnEmitCalls = append(p.OnEmitCalls, emitArgs{ctx, r})
return p.ReturnErr
}

func (p *processor) Enabled(ctx context.Context, r log.Record) bool {
p.EnabledCalls = append(p.EnabledCalls, args{ctx, &r})
func (p *processor) Enabled(ctx context.Context, param api.EnabledParameters) bool {
p.EnabledCalls = append(p.EnabledCalls, enabledArgs{ctx, param})
return true
}

Expand Down Expand Up @@ -105,14 +110,14 @@ func TestLogProcessorEnabled(t *testing.T) {

p := NewLogProcessor(wrapped, api.SeverityTrace1)
ctx := context.Background()
r := &log.Record{}
param := api.EnabledParameters{}
for _, sev := range severities {
r.SetSeverity(sev)
assert.True(t, p.Enabled(ctx, *r), sev.String())
param.SetSeverity(sev)
assert.True(t, p.Enabled(ctx, param), sev.String())

if assert.Lenf(t, wrapped.EnabledCalls, 1, "Record with severity %s not passed-through", sev) {
assert.Equal(t, ctx, wrapped.EnabledCalls[0].Ctx, sev.String())
assert.Equal(t, r, wrapped.EnabledCalls[0].Record, sev.String())
assert.Equal(t, param, wrapped.EnabledCalls[0].Param, sev.String())
}
wrapped.Reset()
}
Expand All @@ -123,10 +128,10 @@ func TestLogProcessorEnabled(t *testing.T) {

p := NewLogProcessor(wrapped, api.SeverityFatal4+1)
ctx := context.Background()
r := &log.Record{}
param := api.EnabledParameters{}
for _, sev := range severities {
r.SetSeverity(sev)
assert.False(t, p.Enabled(ctx, *r), sev.String())
param.SetSeverity(sev)
assert.False(t, p.Enabled(ctx, param), sev.String())

if !assert.Lenf(t, wrapped.EnabledCalls, 0, "Record with severity %s passed-through", sev) {
wrapped.Reset()
Expand Down Expand Up @@ -158,9 +163,11 @@ func TestLogProcessorNilDownstream(t *testing.T) {
ctx := context.Background()
r := new(log.Record)
r.SetSeverity(api.SeverityTrace1)
param := api.EnabledParameters{}
param.SetSeverity(api.SeverityTrace1)
assert.NotPanics(t, func() {
assert.NoError(t, p.OnEmit(ctx, r))
assert.False(t, p.Enabled(ctx, *r))
assert.False(t, p.Enabled(ctx, param))
assert.NoError(t, p.ForceFlush(ctx))
assert.NoError(t, p.Shutdown(ctx))
})
Expand All @@ -169,6 +176,8 @@ func TestLogProcessorNilDownstream(t *testing.T) {
func BenchmarkLogProcessor(b *testing.B) {
r := new(log.Record)
r.SetSeverity(api.SeverityTrace)
param := api.EnabledParameters{}
param.SetSeverity(api.SeverityTrace)
ctx := context.Background()

type combo interface {
Expand All @@ -182,7 +191,7 @@ func BenchmarkLogProcessor(b *testing.B) {
var enabled bool
b.ReportAllocs()
for n := 0; n < b.N; n++ {
enabled = p.Enabled(ctx, *r)
enabled = p.Enabled(ctx, param)
err = p.OnEmit(ctx, r)
}

Expand Down

0 comments on commit 1bd570f

Please sign in to comment.