-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk/log: Add FilterProcessor and EnabledParameters (#6317)
Per #6271 (comment) > We agreed that we can move `FilterProcessor` directly to `sdk/log` as Logs SDK does not look to be stabilized soon. - Add the possibility to filter based on the resource and scope which is available for the SDK. The scope information is the most important as it gives the possibility to e.g. filter out logs emitted for a given logger. Thus e.g. open-telemetry/opentelemetry-specification#4364 is not necessary. See open-telemetry/opentelemetry-specification#4290 (comment) for more context. - It is going be an example for open-telemetry/opentelemetry-specification#4363 There is a little overhead (IMO totally acceptable) because of data transformation. Most importantly, there is no new heap allocation. ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/log cpu: 13th Gen Intel(R) Core(TM) i7-13800H │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ LoggerEnabled-20 4.589n ± 1% 319.750n ± 16% +6867.75% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ LoggerEnabled-20 0.000Ki ± 0% 1.093Ki ± 13% ? (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ LoggerEnabled-20 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ ¹ all samples are equal ``` `Logger.Enabled` is still more efficient than `Logger.Emit` (benchmarks from #6315). ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/log cpu: 13th Gen Intel(R) Core(TM) i7-13800H BenchmarkLoggerEmit/5_attributes-20 559934 2391 ns/op 39088 B/op 1 allocs/op BenchmarkLoggerEmit/10_attributes-20 1000000 5910 ns/op 49483 B/op 5 allocs/op BenchmarkLoggerEnabled-20 1605697 968.7 ns/op 1272 B/op 0 allocs/op PASS ok go.opentelemetry.io/otel/sdk/log 10.789s ``` Prior art: - #6271 - #6286 I also created for tracking purposes: - #6328
- Loading branch information
Showing
12 changed files
with
145 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package log // import "go.opentelemetry.io/otel/sdk/log" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/otel/log" | ||
"go.opentelemetry.io/otel/sdk/instrumentation" | ||
"go.opentelemetry.io/otel/sdk/resource" | ||
) | ||
|
||
// FilterProcessor is a [Processor] that knows, and can identify, what [Record] | ||
// it will process or drop when it is passed to [Processor.OnEmit]. | ||
// | ||
// This is useful for users that want to know if a [log.Record] | ||
// will be processed or dropped before they perform complex operations to | ||
// construct the [log.Record]. | ||
// | ||
// The SDK's Logger.Enabled returns false | ||
// if all the registered Processors implement FilterProcessor | ||
// and they all return false. | ||
// | ||
// Processor implementations that choose to support this by satisfying this | ||
// interface are expected to re-evaluate the [Record] passed to [Processor.OnEmit], | ||
// it is not expected that the caller to OnEmit will use the functionality | ||
// from this interface prior to calling OnEmit. | ||
// | ||
// See the [go.opentelemetry.io/contrib/processors/minsev] for an example use-case. | ||
// It provides a Processor used to filter out [Record] | ||
// that has a [log.Severity] below a threshold. | ||
type FilterProcessor interface { | ||
// Enabled returns whether the Processor will process for the given context | ||
// and param. | ||
// | ||
// The passed param is likely to be a partial record information being | ||
// provided (e.g a param with only the Severity set). | ||
// If a Processor needs more information than is provided, it | ||
// is said to be in an indeterminate state (see below). | ||
// | ||
// The returned value will be true when the Processor will process for the | ||
// provided context and param, and will be false if the Logger will not | ||
// emit. The returned value may be true or false in an indeterminate state. | ||
// 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, correctness). | ||
// | ||
// The param should not be held by the implementation. A copy should be | ||
// made if the param needs to be held after the call returns. | ||
// | ||
// Implementations of this method need to be safe for a user to call | ||
// concurrently. | ||
Enabled(ctx context.Context, param EnabledParameters) bool | ||
} | ||
|
||
// EnabledParameters represents payload for [FilterProcessor]'s Enabled method. | ||
type EnabledParameters struct { | ||
Resource resource.Resource | ||
InstrumentationScope instrumentation.Scope | ||
Severity log.Severity | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.