diff --git a/bridges/otellogr/go.mod b/bridges/otellogr/go.mod index 77513f200de..8679e6d578d 100644 --- a/bridges/otellogr/go.mod +++ b/bridges/otellogr/go.mod @@ -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 ( diff --git a/bridges/otellogr/go.sum b/bridges/otellogr/go.sum index 4ef1221bf13..61163c58071 100644 --- a/bridges/otellogr/go.sum +++ b/bridges/otellogr/go.sum @@ -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= diff --git a/bridges/otellogrus/go.mod b/bridges/otellogrus/go.mod index a7c84a84b80..ae647a6cf44 100644 --- a/bridges/otellogrus/go.mod +++ b/bridges/otellogrus/go.mod @@ -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 ( diff --git a/bridges/otellogrus/go.sum b/bridges/otellogrus/go.sum index 5233002afba..14472b9bb61 100644 --- a/bridges/otellogrus/go.sum +++ b/bridges/otellogrus/go.sum @@ -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= diff --git a/bridges/otelslog/go.mod b/bridges/otelslog/go.mod index ca25c81441c..c825669721a 100644 --- a/bridges/otelslog/go.mod +++ b/bridges/otelslog/go.mod @@ -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 ( diff --git a/bridges/otelslog/go.sum b/bridges/otelslog/go.sum index 4ef1221bf13..61163c58071 100644 --- a/bridges/otelslog/go.sum +++ b/bridges/otelslog/go.sum @@ -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= diff --git a/bridges/otelslog/handler.go b/bridges/otelslog/handler.go index 3cfb5bf02b1..348cf81b1fa 100644 --- a/bridges/otelslog/handler.go +++ b/bridges/otelslog/handler.go @@ -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 diff --git a/bridges/otelslog/handler_test.go b/bridges/otelslog/handler_test.go index 6618e2bed80..761889de2ee 100644 --- a/bridges/otelslog/handler_test.go +++ b/bridges/otelslog/handler_test.go @@ -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) { diff --git a/bridges/otelzap/core.go b/bridges/otelzap/core.go index 594de3e3a6d..962ce5bf315 100644 --- a/bridges/otelzap/core.go +++ b/bridges/otelzap/core.go @@ -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. @@ -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 diff --git a/bridges/otelzap/core_test.go b/bridges/otelzap/core_test.go index 016bb1486b7..0d00794b409 100644 --- a/bridges/otelzap/core_test.go +++ b/bridges/otelzap/core_test.go @@ -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)) diff --git a/bridges/otelzap/go.mod b/bridges/otelzap/go.mod index c63491861b4..2ef2fd00b83 100644 --- a/bridges/otelzap/go.mod +++ b/bridges/otelzap/go.mod @@ -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 ) diff --git a/bridges/otelzap/go.sum b/bridges/otelzap/go.sum index a585c810330..0e563cc8687 100644 --- a/bridges/otelzap/go.sum +++ b/bridges/otelzap/go.sum @@ -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= diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod index ee5533e1dc1..be41c2ff8e9 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod @@ -11,7 +11,7 @@ replace ( require ( github.com/aws/aws-lambda-go v1.47.0 - github.com/aws/aws-sdk-go-v2/config v1.27.33 + github.com/aws/aws-sdk-go-v2/config v1.27.34 github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2 go.opentelemetry.io/contrib/detectors/aws/lambda v0.55.0 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda v0.55.0 diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum index 379e21de145..47554ac235a 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum @@ -4,8 +4,8 @@ github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDy github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4/go.mod h1:/MQxMqci8tlqDH+pjmoLu1i0tbWCUP1hhyMRuFxpQCw= -github.com/aws/aws-sdk-go-v2/config v1.27.33 h1:Nof9o/MsmH4oa0s2q9a0k7tMz5x/Yj5k06lDODWz3BU= -github.com/aws/aws-sdk-go-v2/config v1.27.33/go.mod h1:kEqdYzRb8dd8Sy2pOdEbExTTF5v7ozEXX0McgPE7xks= +github.com/aws/aws-sdk-go-v2/config v1.27.34 h1:5sLceuETg/215nLtY/QIVB2O6cosS0iC/Tx5oyqUhbw= +github.com/aws/aws-sdk-go-v2/config v1.27.34/go.mod h1:kEqdYzRb8dd8Sy2pOdEbExTTF5v7ozEXX0McgPE7xks= github.com/aws/aws-sdk-go-v2/credentials v1.17.32 h1:7Cxhp/BnT2RcGy4VisJ9miUPecY+lyE9I8JvcZofn9I= github.com/aws/aws-sdk-go-v2/credentials v1.17.32/go.mod h1:P5/QMF3/DCHbXGEGkdbilXHsyTBX5D3HSwcrSc9p20I= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 h1:pfQ2sqNpMVK6xz2RbqLEL0GH87JOwSxPV2rzm8Zsb74= diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod index 66e3273cc77..1fa00708641 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod @@ -6,7 +6,7 @@ replace go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2 require ( github.com/aws/aws-sdk-go-v2 v1.30.5 - github.com/aws/aws-sdk-go-v2/config v1.27.33 + github.com/aws/aws-sdk-go-v2/config v1.27.34 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.9 github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.55.0 diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum index 256cc9aa781..b1535797277 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum @@ -2,8 +2,8 @@ github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDy github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4/go.mod h1:/MQxMqci8tlqDH+pjmoLu1i0tbWCUP1hhyMRuFxpQCw= -github.com/aws/aws-sdk-go-v2/config v1.27.33 h1:Nof9o/MsmH4oa0s2q9a0k7tMz5x/Yj5k06lDODWz3BU= -github.com/aws/aws-sdk-go-v2/config v1.27.33/go.mod h1:kEqdYzRb8dd8Sy2pOdEbExTTF5v7ozEXX0McgPE7xks= +github.com/aws/aws-sdk-go-v2/config v1.27.34 h1:5sLceuETg/215nLtY/QIVB2O6cosS0iC/Tx5oyqUhbw= +github.com/aws/aws-sdk-go-v2/config v1.27.34/go.mod h1:kEqdYzRb8dd8Sy2pOdEbExTTF5v7ozEXX0McgPE7xks= github.com/aws/aws-sdk-go-v2/credentials v1.17.32 h1:7Cxhp/BnT2RcGy4VisJ9miUPecY+lyE9I8JvcZofn9I= github.com/aws/aws-sdk-go-v2/credentials v1.17.32/go.mod h1:P5/QMF3/DCHbXGEGkdbilXHsyTBX5D3HSwcrSc9p20I= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 h1:pfQ2sqNpMVK6xz2RbqLEL0GH87JOwSxPV2rzm8Zsb74= diff --git a/processors/minsev/example_test.go b/processors/minsev/example_test.go index 09780092392..0897a8afe00 100644 --- a/processors/minsev/example_test.go +++ b/processors/minsev/example_test.go @@ -10,19 +10,18 @@ import ( "strings" "sync" - api "go.opentelemetry.io/otel/log" - "go.opentelemetry.io/otel/sdk/log" + "go.opentelemetry.io/otel/log" ) const key = "OTEL_LOG_LEVEL" -var getSeverity = sync.OnceValue(func() api.Severity { - conv := map[string]api.Severity{ - "": api.SeverityInfo, // Default to SeverityInfo for unset. - "debug": api.SeverityDebug, - "info": api.SeverityInfo, - "warn": api.SeverityWarn, - "error": api.SeverityError, +var getSeverity = sync.OnceValue(func() log.Severity { + conv := map[string]log.Severity{ + "": log.SeverityInfo, // Default to SeverityInfo for unset. + "debug": log.SeverityDebug, + "info": log.SeverityInfo, + "warn": log.SeverityWarn, + "error": log.SeverityError, } // log.SeverityUnknown for unknown values. return conv[strings.ToLower(os.Getenv(key))] @@ -30,7 +29,7 @@ var getSeverity = sync.OnceValue(func() api.Severity { type EnvSeverity struct{} -func (EnvSeverity) Severity() api.Severity { return getSeverity() } +func (EnvSeverity) Severity() log.Severity { return getSeverity() } func ExampleSeveritier() { // Mock an environment variable setup that would be done externally. @@ -38,12 +37,12 @@ func ExampleSeveritier() { p := NewLogProcessor(&processor{}, EnvSeverity{}) - ctx, r := context.Background(), log.Record{} - r.SetSeverity(api.SeverityDebug) - fmt.Println(p.Enabled(ctx, r)) + ctx, params := context.Background(), log.EnabledParameters{} + params.SetSeverity(log.SeverityDebug) + fmt.Println(p.Enabled(ctx, params)) - r.SetSeverity(api.SeverityError) - fmt.Println(p.Enabled(ctx, r)) + params.SetSeverity(log.SeverityError) + fmt.Println(p.Enabled(ctx, params)) // Output: // false diff --git a/processors/minsev/go.mod b/processors/minsev/go.mod index db55012fbc7..933d5f26da3 100644 --- a/processors/minsev/go.mod +++ b/processors/minsev/go.mod @@ -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 ( diff --git a/processors/minsev/go.sum b/processors/minsev/go.sum index 6407ef430c6..e112a8daaee 100644 --- a/processors/minsev/go.sum +++ b/processors/minsev/go.sum @@ -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= diff --git a/processors/minsev/minsev.go b/processors/minsev/minsev.go index 1aa09a31f70..e4625359193 100644 --- a/processors/minsev/minsev.go +++ b/processors/minsev/minsev.go @@ -8,6 +8,7 @@ package minsev // import "go.opentelemetry.io/contrib/processors/minsev" import ( "context" + api "go.opentelemetry.io/otel/log" "go.opentelemetry.io/otel/sdk/log" ) @@ -39,7 +40,7 @@ func NewLogProcessor(downstream log.Processor, severity Severitier) *LogProcesso // 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 @@ -71,21 +72,26 @@ 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 { + sev, ok := param.Severity() + if !ok { + return true + } + if p.filter != nil { - return record.Severity() >= p.sev.Severity() && - p.filter.Enabled(ctx, record) + return sev >= p.sev.Severity() && + p.filter.Enabled(ctx, param) } - return record.Severity() >= p.sev.Severity() + return sev >= p.sev.Severity() } 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 } diff --git a/processors/minsev/minsev_test.go b/processors/minsev/minsev_test.go index bbc8c98dd91..3f43af455b1 100644 --- a/processors/minsev/minsev_test.go +++ b/processors/minsev/minsev_test.go @@ -26,27 +26,32 @@ type apiSev api.Severity func (s apiSev) Severity() api.Severity { return api.Severity(s) } -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 } @@ -73,20 +78,20 @@ func TestLogProcessorDynamicSeverity(t *testing.T) { p := NewLogProcessor(wrapped, sev) ctx := context.Background() - r := &log.Record{} - r.SetSeverity(api.SeverityDebug) - assert.False(t, p.Enabled(ctx, *r), api.SeverityDebug.String()) + params := &api.EnabledParameters{} + params.SetSeverity(api.SeverityDebug) + assert.False(t, p.Enabled(ctx, *params), api.SeverityDebug.String()) - r.SetSeverity(api.SeverityInfo) - assert.True(t, p.Enabled(ctx, *r), api.SeverityInfo.String()) + params.SetSeverity(api.SeverityInfo) + assert.True(t, p.Enabled(ctx, *params), api.SeverityInfo.String()) sev.Set(SeverityError) - r.SetSeverity(api.SeverityInfo) - assert.False(t, p.Enabled(ctx, *r), api.SeverityInfo.String()) + params.SetSeverity(api.SeverityInfo) + assert.False(t, p.Enabled(ctx, *params), api.SeverityInfo.String()) - r.SetSeverity(api.SeverityError) - assert.True(t, p.Enabled(ctx, *r), api.SeverityError.String()) + params.SetSeverity(api.SeverityError) + assert.True(t, p.Enabled(ctx, *params), api.SeverityError.String()) } func TestLogProcessorOnEmit(t *testing.T) { @@ -131,14 +136,14 @@ func TestLogProcessorEnabled(t *testing.T) { p := NewLogProcessor(wrapped, 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() } @@ -149,10 +154,10 @@ func TestLogProcessorEnabled(t *testing.T) { p := NewLogProcessor(wrapped, apiSev(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() @@ -166,16 +171,16 @@ func TestLogProcessorEnabled(t *testing.T) { pruned := struct{ log.Processor }{wrapped} // Remove the Enabled method. p := NewLogProcessor(pruned, SeverityInfo) ctx := context.Background() - r := &log.Record{} + params := &api.EnabledParameters{} - r.SetSeverity(api.SeverityDebug) - assert.False(t, p.Enabled(ctx, *r)) + params.SetSeverity(api.SeverityDebug) + assert.False(t, p.Enabled(ctx, *params)) - r.SetSeverity(api.SeverityInfo) - assert.True(t, p.Enabled(ctx, *r)) + params.SetSeverity(api.SeverityInfo) + assert.True(t, p.Enabled(ctx, *params)) - r.SetSeverity(api.SeverityError) - assert.True(t, p.Enabled(ctx, *r)) + params.SetSeverity(api.SeverityError) + assert.True(t, p.Enabled(ctx, *params)) assert.Len(t, wrapped.EnabledCalls, 0) }) @@ -209,9 +214,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)) }) @@ -220,6 +227,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 { @@ -233,7 +242,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) }