Skip to content

Commit 5bc1f13

Browse files
trasklmolkovapellared
authored
Add minimum_severity and trace_based logger configuration parameters (#4612)
Alternative to #4611 Some related prior discussions: - #4208 (comment) - #4207 (comment) Java POC @ open-telemetry/opentelemetry-java#7529 Declarative config for this is a bit nicer than in #4611, also supports applying different minimum severity levels to different loggers: ``` file_format: "1.0" logger_provider: logger_configurator/development: default_config: minimum_severity: WARN trace_based: true loggers: - name: "com.example.app.*" config: minimum_severity: INFO - name: "com.example.db.*" config: minimum_severity: ERROR ``` --------- Co-authored-by: Liudmila Molkova <[email protected]> Co-authored-by: Robert Pająk <[email protected]>
1 parent 7295dc4 commit 5bc1f13

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

specification/logs/sdk.md

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ accommodate common use cases:
129129
* Select one or more loggers by name, with exact match or pattern matching.
130130
* Disable one or more specific loggers.
131131
* Disable all loggers, and selectively enable one or more specific loggers.
132+
* Set the minimum severity levels for specific loggers or logger patterns.
133+
* Enable trace-based filtering for specific loggers or logger patterns.
132134

133135
### Shutdown
134136

@@ -192,24 +194,63 @@ It consists of the following parameters:
192194
If a `Logger` is disabled, it MUST behave equivalently
193195
to [No-op Logger](./noop.md#logger).
194196

195-
The value of `disabled` MUST be used to resolve whether a `Logger`
196-
is [Enabled](./api.md#enabled). If `disabled` is `true`, `Enabled`
197-
returns `false`. If `disabled` is `false`, `Enabled` returns `true`. It is not
198-
necessary for implementations to ensure that changes to `disabled` are
199-
immediately visible to callers of `Enabled`.
197+
* `minimum_severity`: A [SeverityNumber](./data-model.md#field-severitynumber)
198+
indicating the minimum severity level for log records to be processed.
199+
200+
If not explicitly set, the `minimum_severity` parameter MUST default to `0`.
201+
202+
If a log record's [SeverityNumber](./data-model.md#field-severitynumber) is
203+
specified (i.e. not `0`) and is less than the configured `minimum_severity`, the log record MUST
204+
be dropped by the `Logger`. Log records with an unspecified severity (i.e. `0`) are not
205+
affected by this parameter and therefore bypass minimum severity filtering.
206+
207+
* `trace_based`: A boolean indication of whether the logger should
208+
only process log records associated with sampled traces.
209+
210+
If not explicitly set, the `trace_based` parameter MUST default to `false`.
211+
212+
If `trace_based` is `true`, log records associated with unsampled traces MUST
213+
be dropped by the `Logger`. A log record is considered associated with an unsampled trace
214+
if it has a valid `SpanId` and its `TraceFlags` indicate that the trace is unsampled.
215+
Log records that aren't associated with a trace
216+
context are not affected by this parameter and therefore bypass trace-based filtering.
217+
218+
It is not necessary for implementations to ensure that changes to any of these
219+
parameters are immediately visible to callers of `Enabled`.
200220

201221
### Emit a LogRecord
202222

203223
If [Observed Timestamp](./data-model.md#field-observedtimestamp) is unspecified,
204224
the implementation SHOULD set it equal to the current time.
205225

226+
**Status**: [Development](../document-status.md) Before processing a log record,
227+
the implementation MUST apply the filtering rules defined by the
228+
[LoggerConfig](#loggerconfig) (in case `Enabled` was not called prior to
229+
emitting the record):
230+
231+
1. **Minimum severity**: If the log record's
232+
[SeverityNumber](./data-model.md#field-severitynumber) is specified
233+
(i.e. not `0`) and is less than the configured `minimum_severity`, the log
234+
record MUST be dropped.
235+
236+
2. **Trace-based**: If `trace_based` is `true`, and if the log record has a
237+
[`SpanId`](./data-model.md#field-spanid) and the
238+
[`TraceFlags`](./data-model.md#field-traceflags) SAMPLED flag is unset,
239+
the log record MUST be dropped.
240+
206241
### Enabled
207242

208243
`Enabled` MUST return `false` when either:
209244

210-
- there are no registered [`LogRecordProcessors`](#logrecordprocessor),
245+
- there are no registered [`LogRecordProcessors`](#logrecordprocessor).
211246
- **Status**: [Development](../document-status.md) - `Logger` is disabled
212-
([`LoggerConfig.disabled`](#loggerconfig) is `true`),
247+
([`LoggerConfig.disabled`](#loggerconfig) is `true`).
248+
- **Status**: [Development](../document-status.md) - the provided severity
249+
is specified (i.e. not `0`) and is less than the configured `minimum_severity` in the
250+
[`LoggerConfig`](#loggerconfig).
251+
- **Status**: [Development](../document-status.md) - `trace_based` is
252+
`true` in the [`LoggerConfig`](#loggerconfig) and the current context is
253+
associated with an unsampled trace.
213254
- **Status**: [Development](../document-status.md) - all registered
214255
`LogRecordProcessors` implement [`Enabled`](#enabled-1),
215256
and a call to `Enabled` on each of them returns `false`.

0 commit comments

Comments
 (0)