Skip to content

Commit 91010b0

Browse files
committed
Revert "Move log.Processor.Enabled to independent FilterProcessor interfaced type (open-telemetry#5692)"
This reverts commit 002c0a4.
1 parent 23f7b41 commit 91010b0

File tree

14 files changed

+72
-193
lines changed

14 files changed

+72
-193
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ The next release will require at least [Go 1.22].
6565
- `SimpleProcessor.Enabled` in `go.opentelemetry.io/otel/sdk/log` now returns `false` if the exporter is `nil`. (#5665)
6666
- Update the concurrency requirements of `Exporter` in `go.opentelemetry.io/otel/sdk/log`. (#5666)
6767
- `SimpleProcessor` in `go.opentelemetry.io/otel/sdk/log` synchronizes `OnEmit` calls. (#5666)
68-
- The `Processor` interface in `go.opentelemetry.io/otel/sdk/log` no longer includes the `Enabled` method.
69-
See the `FilterProcessor` interface type added in `go.opentelemetry.io/otel/sdk/log/internal/x` to continue providing this functionality. (#5692)
7068
- The `SimpleProcessor` type in `go.opentelemetry.io/otel/sdk/log` is no longer comparable. (#5693)
7169
- The `BatchProcessor` type in `go.opentelemetry.io/otel/sdk/log` is no longer comparable. (#5693)
7270

sdk/log/batch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ func (b *BatchProcessor) OnEmit(_ context.Context, r *Record) error {
196196
return nil
197197
}
198198

199+
// Enabled returns if b is enabled.
200+
func (b *BatchProcessor) Enabled(context.Context, Record) bool {
201+
return !b.stopped.Load() && b.q != nil
202+
}
203+
199204
// Shutdown flushes queued log records and shuts down the decorated exporter.
200205
func (b *BatchProcessor) Shutdown(ctx context.Context) error {
201206
if b.stopped.Swap(true) || b.q == nil {

sdk/log/batch_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestEmptyBatchConfig(t *testing.T) {
4747
ctx := context.Background()
4848
record := new(Record)
4949
assert.NoError(t, bp.OnEmit(ctx, record), "OnEmit")
50+
assert.False(t, bp.Enabled(ctx, *record), "Enabled")
5051
assert.NoError(t, bp.ForceFlush(ctx), "ForceFlush")
5152
assert.NoError(t, bp.Shutdown(ctx), "Shutdown")
5253
})
@@ -269,6 +270,14 @@ func TestBatchProcessor(t *testing.T) {
269270
assert.Equal(t, 3, e.ExportN())
270271
})
271272

273+
t.Run("Enabled", func(t *testing.T) {
274+
b := NewBatchProcessor(defaultNoopExporter)
275+
assert.True(t, b.Enabled(ctx, Record{}))
276+
277+
_ = b.Shutdown(ctx)
278+
assert.False(t, b.Enabled(ctx, Record{}))
279+
})
280+
272281
t.Run("Shutdown", func(t *testing.T) {
273282
t.Run("Error", func(t *testing.T) {
274283
e := newTestExporter(assert.AnError)

sdk/log/doc.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,5 @@ at a single endpoint their origin is decipherable.
3232
3333
See [go.opentelemetry.io/otel/log] for more information about
3434
the OpenTelemetry Logs Bridge API.
35-
36-
See [go.opentelemetry.io/otel/sdk/log/internal/x] for information about the
37-
experimental features.
3835
*/
3936
package log // import "go.opentelemetry.io/otel/sdk/log"

sdk/log/example_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"strings"
10-
"sync"
1110

1211
logapi "go.opentelemetry.io/otel/log"
1312
"go.opentelemetry.io/otel/log/global"
@@ -59,7 +58,7 @@ func ExampleProcessor_filtering() {
5958
// Wrap the processor so that it ignores processing log records
6059
// when a context deriving from WithIgnoreLogs is passed
6160
// to the logging methods.
62-
processor = &ContextFilterProcessor{Processor: processor}
61+
processor = &ContextFilterProcessor{processor}
6362

6463
// The created processor can then be registered with
6564
// the OpenTelemetry Logs SDK using the WithProcessor option.
@@ -82,15 +81,6 @@ func WithIgnoreLogs(ctx context.Context) context.Context {
8281
// [WithIgnoreLogs] is passed to its methods.
8382
type ContextFilterProcessor struct {
8483
log.Processor
85-
86-
lazyFilter sync.Once
87-
// Use the experimental FilterProcessor interface
88-
// (go.opentelemetry.io/otel/sdk/log/internal/x).
89-
filter filter
90-
}
91-
92-
type filter interface {
93-
Enabled(ctx context.Context, param logapi.EnabledParameters) bool
9484
}
9585

9686
func (p *ContextFilterProcessor) OnEmit(ctx context.Context, record *log.Record) error {
@@ -100,13 +90,8 @@ func (p *ContextFilterProcessor) OnEmit(ctx context.Context, record *log.Record)
10090
return p.Processor.OnEmit(ctx, record)
10191
}
10292

103-
func (p *ContextFilterProcessor) Enabled(ctx context.Context, param logapi.EnabledParameters) bool {
104-
p.lazyFilter.Do(func() {
105-
if f, ok := p.Processor.(filter); ok {
106-
p.filter = f
107-
}
108-
})
109-
return !ignoreLogs(ctx) && (p.filter == nil || p.filter.Enabled(ctx, param))
93+
func (p *ContextFilterProcessor) Enabled(ctx context.Context, record log.Record) bool {
94+
return !ignoreLogs(ctx) && p.Processor.Enabled(ctx, record)
11095
}
11196

11297
func ignoreLogs(ctx context.Context) bool {
@@ -135,6 +120,10 @@ func ExampleProcessor_redact() {
135120
// from attributes containing "token" in the key.
136121
type RedactTokensProcessor struct{}
137122

123+
func (p *RedactTokensProcessor) Enabled(ctx context.Context, record log.Record) bool {
124+
return true
125+
}
126+
138127
// OnEmit redacts values from attributes containing "token" in the key
139128
// by replacing them with a REDACTED value.
140129
func (p *RedactTokensProcessor) OnEmit(ctx context.Context, record *log.Record) error {

sdk/log/internal/x/README.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

sdk/log/internal/x/x.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

sdk/log/logger.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"go.opentelemetry.io/otel/log"
1212
"go.opentelemetry.io/otel/log/embedded"
1313
"go.opentelemetry.io/otel/sdk/instrumentation"
14-
"go.opentelemetry.io/otel/sdk/log/internal/x"
1514
"go.opentelemetry.io/otel/trace"
1615
)
1716

@@ -43,29 +42,14 @@ func (l *logger) Emit(ctx context.Context, r log.Record) {
4342
}
4443
}
4544

46-
// Enabled returns true if at least one Processor held by the LoggerProvider
47-
// that created the logger will process param for the provided context and param.
48-
//
49-
// If it is not possible to definitively determine the param will be
50-
// processed, true will be returned by default. A value of false will only be
51-
// returned if it can be positively verified that no Processor will process.
52-
func (l *logger) Enabled(ctx context.Context, param log.EnabledParameters) bool {
53-
fltrs := l.provider.filterProcessors()
54-
// If there are more Processors than FilterProcessors we cannot be sure
55-
// that all Processors will drop the record. Therefore, return true.
56-
//
57-
// If all Processors are FilterProcessors, check if any is enabled.
58-
return len(l.provider.processors) > len(fltrs) || anyEnabled(ctx, param, fltrs)
59-
}
60-
61-
func anyEnabled(ctx context.Context, param log.EnabledParameters, fltrs []x.FilterProcessor) bool {
62-
for _, f := range fltrs {
63-
if f.Enabled(ctx, param) {
64-
// At least one Processor will process the Record.
65-
return true
66-
}
67-
}
68-
// No Processor will process the record
45+
func (l *logger) Enabled(ctx context.Context, r log.EnabledParameters) bool {
46+
// TODO
47+
// newRecord := l.newRecord(ctx, r)
48+
// for _, p := range l.provider.processors {
49+
// if enabled := p.Enabled(ctx, newRecord); enabled {
50+
// return true
51+
// }
52+
// }
6953
return false
7054
}
7155

sdk/log/logger_test.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ func TestLoggerEmit(t *testing.T) {
215215
}
216216

217217
func TestLoggerEnabled(t *testing.T) {
218-
p0 := newFltrProcessor("0", true)
219-
p1 := newFltrProcessor("1", true)
220-
p2WithDisabled := newFltrProcessor("2", false)
218+
p0, p1, p2WithDisabled := newProcessor("0"), newProcessor("1"), newProcessor("2")
219+
p2WithDisabled.enabled = false
221220

222221
testCases := []struct {
223222
name string
@@ -274,24 +273,3 @@ func TestLoggerEnabled(t *testing.T) {
274273
})
275274
}
276275
}
277-
278-
func BenchmarkLoggerEnabled(b *testing.B) {
279-
provider := NewLoggerProvider(
280-
WithProcessor(newFltrProcessor("0", false)),
281-
WithProcessor(newFltrProcessor("1", true)),
282-
)
283-
logger := provider.Logger("BenchmarkLoggerEnabled")
284-
ctx, param := context.Background(), log.EnabledParameters{}
285-
param.SetSeverity(log.SeverityDebug)
286-
287-
var enabled bool
288-
289-
b.ReportAllocs()
290-
b.ResetTimer()
291-
292-
for n := 0; n < b.N; n++ {
293-
enabled = logger.Enabled(ctx, param)
294-
}
295-
296-
_ = enabled
297-
}

sdk/log/processor.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import (
1212
// Any of the Processor's methods may be called concurrently with itself
1313
// or with other methods. It is the responsibility of the Processor to manage
1414
// this concurrency.
15-
//
16-
// See [go.opentelemetry.io/otel/sdk/log/internal/x] for information about how
17-
// a Processor can be extended to support experimental features.
1815
type Processor interface {
1916
// OnEmit is called when a Record is emitted.
2017
//
@@ -38,6 +35,27 @@ type Processor interface {
3835
// to create a copy that shares no state with the original.
3936
OnEmit(ctx context.Context, record *Record) error
4037

38+
// Enabled returns whether the Processor will process for the given context
39+
// and record.
40+
//
41+
// The passed record is likely to be a partial record with only the
42+
// bridge-relevant information being provided (e.g a record with only the
43+
// Severity set). If a Logger needs more information than is provided, it
44+
// is said to be in an indeterminate state (see below).
45+
//
46+
// The returned value will be true when the Processor will process for the
47+
// provided context and record, and will be false if the Processor will not
48+
// process. The returned value may be true or false in an indeterminate
49+
// state. An implementation should default to returning true for an
50+
// indeterminate state, but may return false if valid reasons in particular
51+
// circumstances exist (e.g. performance, correctness).
52+
//
53+
// The SDK invokes the processors sequentially in the same order as
54+
// they were registered using [WithProcessor] until any processor returns true.
55+
//
56+
// Implementations should not modify the record.
57+
Enabled(ctx context.Context, record Record) bool
58+
4159
// Shutdown is called when the SDK shuts down. Any cleanup or release of
4260
// resources held by the exporter should be done in this call.
4361
//

sdk/log/provider.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"go.opentelemetry.io/otel/log/embedded"
1616
"go.opentelemetry.io/otel/log/noop"
1717
"go.opentelemetry.io/otel/sdk/instrumentation"
18-
"go.opentelemetry.io/otel/sdk/log/internal/x"
1918
"go.opentelemetry.io/otel/sdk/resource"
2019
)
2120

@@ -67,9 +66,6 @@ type LoggerProvider struct {
6766
attributeCountLimit int
6867
attributeValueLengthLimit int
6968

70-
fltrProcessorsOnce sync.Once
71-
fltrProcessors []x.FilterProcessor
72-
7369
loggersMu sync.Mutex
7470
loggers map[instrumentation.Scope]*logger
7571

@@ -97,17 +93,6 @@ func NewLoggerProvider(opts ...LoggerProviderOption) *LoggerProvider {
9793
}
9894
}
9995

100-
func (p *LoggerProvider) filterProcessors() []x.FilterProcessor {
101-
p.fltrProcessorsOnce.Do(func() {
102-
for _, proc := range p.processors {
103-
if f, ok := proc.(x.FilterProcessor); ok {
104-
p.fltrProcessors = append(p.fltrProcessors, f)
105-
}
106-
}
107-
})
108-
return p.fltrProcessors
109-
}
110-
11196
// Logger returns a new [log.Logger] with the provided name and configuration.
11297
//
11398
// If p is shut down, a [noop.Logger] instance is returned.

0 commit comments

Comments
 (0)