Skip to content

Commit

Permalink
Fix minsev
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 23, 2024
1 parent fc6bf2e commit 2f3382a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 16 additions & 2 deletions processors/minsev/minsev.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ func NewLogProcessor(downstream log.Processor, minimum api.Severity) *LogProcess
if downstream == nil {
downstream = defaultProcessor
}
return &LogProcessor{Processor: downstream, Minimum: minimum}
p := &LogProcessor{Processor: downstream, Minimum: minimum}
if fp, ok := downstream.(filterProcessor); ok {
p.filter = fp
}
return p
}

// 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
}

// LogProcessor is an [log.Processor] implementation that wraps another
Expand All @@ -35,6 +45,7 @@ func NewLogProcessor(downstream log.Processor, minimum api.Severity) *LogProcess
type LogProcessor struct {
log.Processor

filter filterProcessor
Minimum api.Severity
}

Expand All @@ -55,7 +66,10 @@ func (p *LogProcessor) OnEmit(ctx context.Context, record *log.Record) error {
// severity of record is greater than or equal to p.Minimum. Otherwise false is
// returned.
func (p *LogProcessor) Enabled(ctx context.Context, record log.Record) bool {
return record.Severity() >= p.Minimum && p.Processor.Enabled(ctx, record)
if p.filter != nil {
return record.Severity() >= p.Minimum && p.filter.Enabled(ctx, record)
}
return record.Severity() >= p.Minimum

Check warning on line 72 in processors/minsev/minsev.go

View check run for this annotation

Codecov / codecov/patch

processors/minsev/minsev.go#L72

Added line #L72 was not covered by tests
}

var defaultProcessor = noopProcessor{}
Expand Down
7 changes: 6 additions & 1 deletion processors/minsev/minsev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func BenchmarkLogProcessor(b *testing.B) {
r.SetSeverity(api.SeverityTrace)
ctx := context.Background()

run := func(p log.Processor) func(b *testing.B) {
type combo interface {
log.Processor
filterProcessor
}

run := func(p combo) func(b *testing.B) {
return func(b *testing.B) {
var err error
var enabled bool
Expand Down

0 comments on commit 2f3382a

Please sign in to comment.