Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ release.

- Clarify STDOUT exporter format is unspecified.
([#4418](https://github.com/open-telemetry/opentelemetry-specification/pull/4418))
- Add `Enabled` opt-in operation to the `LogRecordProcessor`.
([#4439](https://github.com/open-telemetry/opentelemetry-specification/pull/4439))

### Baggage

Expand Down
1 change: 1 addition & 0 deletions spec-compliance-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ Disclaimer: this list of features is still a work in progress, please refer to t
| SimpleLogRecordProcessor | | | + | | + | | | + | | + | | |
| BatchLogRecordProcessor | | | + | | + | | | + | | + | | |
| Can plug custom LogRecordProcessor | | | + | | + | | | + | | + | | |
| Opt-in LogRecordProcessor.Enabled | | | + | | + | | | + | | + | | |
| OTLP/gRPC exporter | | | + | | + | | | + | | + | + | |
| OTLP/HTTP exporter | | | + | | + | | | + | | + | + | |
| OTLP File exporter | | | - | | - | | | | | + | - | |
Expand Down
38 changes: 37 additions & 1 deletion specification/logs/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- [LogRecordProcessor](#logrecordprocessor)
* [LogRecordProcessor operations](#logrecordprocessor-operations)
+ [OnEmit](#onemit)
+ [Enabled](#enabled-1)
+ [ShutDown](#shutdown)
+ [ForceFlush](#forceflush-1)
* [Built-in processors](#built-in-processors)
Expand Down Expand Up @@ -198,7 +199,9 @@ It consists of the following parameters:
`Enabled` MUST return `false` when:

- there are no registered [`LogRecordProcessors`](#logrecordprocessor),
- `Logger` is disabled ([`LoggerConfig.disabled`](#loggerconfig) is `true`).
- `Logger` is disabled ([`LoggerConfig.disabled`](#loggerconfig) is `true`),
- all registered `LogRecordProcessors` implement [`Enabled`](#enabled-1),
and a call to `Enabled` on each of them returns `false`.

Otherwise, it SHOULD return `true`.
It MAY return `false` to support additional optimizations and features.
Expand Down Expand Up @@ -345,6 +348,39 @@ A `LogRecordProcessor` may freely modify `logRecord` for the duration of
the `OnEmit` call. If `logRecord` is needed after `OnEmit` returns (i.e. for
asynchronous processing) only reads are permitted.

#### Enabled

**Status**: [Development](../document-status.md)

`Enabled` is an opt-in operation that a `LogRecordProcessor` MAY implement
in order to support filtering via [`Logger.Enabled`](api.md#enabled).

**Parameters:**

* [Resource](./data-model.md#field-resource) associated with the `LoggerProvider`
* [Instrumentation Scope](./data-model.md#field-instrumentationscope) associated
with the `Logger`
* [Context](../context/README.md) explicitly passed by the caller or the current
Context
* [Severity Number](./data-model.md#field-severitynumber) passed by the caller

**Returns:** `Boolean`

Any modifications to parameters inside `Enabled` MUST NOT be propagated to the
caller. Parameters are immutable or passed by value.

An implementation should default to returning `true` for an indeterminate
state, but may return `false` if valid reasons in particular circumstances
exist (e.g. performance).

`LogRecordProcessor` implementations that choose to support this operation are
expected to re-evaluate the [ReadWriteLogRecord](#readwritelogrecord) passed to
[`OnEmit`](#onemit). It is not expected that the caller to `OnEmit` will use the
functionality from this operation prior to calling `OnEmit`.

This operation is usually called synchronously, therefore it should not block
or throw exceptions.

#### ShutDown

Shuts down the processor. Called when the SDK is shut down. This is an
Expand Down
59 changes: 59 additions & 0 deletions specification/logs/supplementary-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ func (p *SeverityProcessor) OnEmit(ctx context.Context, record *sdklog.Record) e
}
return p.Processor.OnEmit(ctx, record)
}

// Enabled returns false if the severity is lower than p.Min.
func (p *SeverityProcessor) Enabled(ctx context.Context, param sdklog.EnabledParameters) bool {
sev := param.Severity
if sev != log.SeverityUndefined && sev < p.Min {
return false
}
if fp, ok := p.Processor.(sdklog.FilterProcessor); ok {
// The wrapped processor is also a filtering processor.
return p.Processor.Enabled(ctx, param)
}
return true
}
```

> [!NOTE]
Expand Down Expand Up @@ -242,6 +255,29 @@ func (p *IsolatedProcessor) OnEmit(ctx context.Context, record *log.Record) erro
}
return rErr
}

// Enabled honors Enabled of the wrapped processors.
func (p *IsolatedProcessor) Enabled(ctx context.Context, param sdklog.EnabledParameters) bool {
fltrProcessors := make([]sdklog.FilterProcessor, len(p.Processors))
for i, proc := range p.Processors {
fp, ok := proc.(sdklog.FilterProcessor)
if !ok {
// Processor not implementing Enabled.
// We assume it will be processed.
return true
}
fltrProcessors[i] = fp
}

for _, proc := range fltrProcessors {
if proc.Enabled(ctx, param) {
// At least one Processor will process the Record.
return true
}
}
// No processor will process the record.
return false
}
```

#### Routing
Expand Down Expand Up @@ -271,6 +307,29 @@ func (p *LogEventRouteProcessor) OnEmit(ctx context.Context, record *log.Record)
}
return p.LogProcessor.OnEmit(ctx, record)
}

// Enabled honors Enabled of the wrapped processors.
func (p *LogEventRouteProcessor) Enabled(ctx context.Context, param sdklog.EnabledParameters) bool {
fp1, ok := p.EventProcessor.(sdklog.FilterProcessor)
if !ok {
// Processor not implementing Enabled.
return true
}
fp2, ok := p.LogProcessor.(sdklog.FilterProcessor)
if !ok {
// Processor not implementing Enabled.
return true
}

if fp1.Enabled(ctx, param) {
return true
}
if fp2.Enabled(ctx, param) {
return true
}
// No processor will process the record.
return false
}
```

#### Setup
Expand Down