Skip to content

Commit

Permalink
Merge branch 'main' into minsev-dyn-sev
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Sep 17, 2024
2 parents 6fbd500 + 1bd570f commit 15f268e
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 93 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
29 changes: 14 additions & 15 deletions processors/minsev/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,39 @@ 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))]
})

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.
_ = os.Setenv(key, "error")

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
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
26 changes: 16 additions & 10 deletions processors/minsev/minsev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

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

0 comments on commit 15f268e

Please sign in to comment.