Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
65 changes: 65 additions & 0 deletions specification/logs/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ weight: 3
* [Built-in processors](#built-in-processors)
+ [Simple processor](#simple-processor)
+ [Batching processor](#batching-processor)
+ [Severity filter](#severity-filter)
+ [Trace based filter](#trace-based-filter)
- [LogRecordExporter](#logrecordexporter)
* [LogRecordExporter operations](#logrecordexporter-operations)
+ [Export](#export)
Expand Down Expand Up @@ -456,6 +458,10 @@ make the flush timeout configurable.
The standard OpenTelemetry SDK MUST implement both simple and batch processors,
as described below.

**Status**: [Development](../document-status.md) - The SDK SHOULD implement the
[severity filter](#severity-filter) and [trace based filter](#trace-based-filter),
as described below.

Other common processing scenarios SHOULD be first considered
for implementation out-of-process
in [OpenTelemetry Collector](../overview.md#collector).
Expand Down Expand Up @@ -495,6 +501,65 @@ to make sure that they are not invoked concurrently.
* `maxExportBatchSize` - the maximum batch size of every export. It must be
smaller or equal to `maxQueueSize`. The default value is `512`.

#### Severity filter

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

This processor wraps another processor (such as the
[batching processor](#batching-processor)) to filter log records
based on their [SeverityNumber](./data-model.md#field-severitynumber).

See the [supplementary guidelines](./supplementary-guidelines.md#filtering)
for an implementation example.

**Required operations:**

* [`Enabled`](#enabled-1) - MUST forward to the delegate if the
[`SeverityNumber`](./data-model.md#field-severitynumber) is unspecified (`0`)
or greater than or equal to the configured `severity` (returning `true` in
this case if the delegate does not implement the optional `Enabled`
operation). Otherwise, MUST return `false`.
* [`OnEmit`](#onemit) - MUST forward to the delegate if the
[`SeverityNumber`](./data-model.md#field-severitynumber) is unspecified (`0`)
or greater than or equal to the configured `severity`.
Otherwise, MUST NOT forward to the delegate.
* [`Shutdown`](#shutdown) - MUST forward to the delegate.
* [`ForceFlush`](#forceflush-1) - MUST forward to the delegate.

**Configurable parameters:**

* `severity` - The minimum severity level required for log records to be
passed to the delegate processor.
* `delegate` - The processor to delegate to for log records that pass
the severity filter.

#### Trace based filter

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

This processor wraps another processor (such as the
[batching processor](#batching-processor)) to filter log records
based on their associated [trace sampling flag](./data-model.md#field-traceflags).

**Required operations:**

* [`Enabled`](#enabled-1) - MUST forward to the delegate if the
[`TraceFlags`](./data-model.md#field-traceflags) SAMPLED flag is set or
the [`SpanId`](./data-model.md#field-spanid) is not present (returning `true`
in this case if the delegate does not implement the optional `Enabled`
operation). Otherwise, MUST return `false`.
* [`OnEmit`](#onemit) - MUST forward to the delegate if the
[`TraceFlags`](./data-model.md#field-traceflags) SAMPLED flag is set or
the [`SpanId`](./data-model.md#field-spanid) is not present.
Otherwise, MUST NOT forward to the delegate.
* [`Shutdown`](#shutdown) - MUST forward to the delegate.
* [`ForceFlush`](#forceflush-1) - MUST forward to the delegate.

**Configurable parameters:**

* `delegate` - The processor to delegate to for log records that pass
the trace-based filter.

## LogRecordExporter

`LogRecordExporter` defines the interface that protocol-specific exporters must
Expand Down
8 changes: 4 additions & 4 deletions specification/logs/supplementary-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ type SeverityProcessor struct {
}

// OnEmit passes ctx and record to the wrapped sdklog.Processor
// if the record's severity is greater than or equal to p.Min.
// if the record's severity is greater than or equal to p.Min, or if the severity is 0 (unspecified).
// Otherwise, the record is dropped (the wrapped processor is not invoked).
func (p *SeverityProcessor) OnEmit(ctx context.Context, record *sdklog.Record) error {
if record.Severity() < p.Min {
if record.Severity() < p.Min && record.Severity() != 0 {
return nil
}
return p.Processor.OnEmit(ctx, record)
}

// Enabled returns false if the severity is lower than p.Min.
// Enabled returns false if the severity is lower than p.Min and is not 0 (unspecified).
func (p *SeverityProcessor) Enabled(ctx context.Context, param sdklog.EnabledParameters) bool {
if param.Severity < p.Min {
if param.Severity < p.Min && param.Severity != 0 {
return false
}
if fp, ok := p.Processor.(sdklog.FilterProcessor); ok {
Expand Down
Loading