1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-26 21:05:00 +02:00

Add the Enabled method to the Logger (#5071)

* Add the Enabled method to the Logger

* Add a changelog entry

* Rename enabled.go to min_sev.go

* Remove MinSeverityProcessor

* Document lack of interaction between OnEmit and Enabled

* Update sdk/log/processor.go

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
Tyler Yahn 2024-03-15 08:15:44 -07:00 committed by GitHub
parent 47ac0d4df8
commit da047e70ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 63 additions and 0 deletions

View File

@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906)
- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906)
- The `Enabled` method is added to the `Logger` interface in `go.opentelemetry.io/otel/log`.
This method is used to notify users if a log record will be emitted or not. (#5071)
- Add `SeverityUndefined` `const` to `go.opentelemetry.io/otel/log`.
This value represents an unset severity level. (#5072)
- Add `Empty` function in `go.opentelemetry.io/otel/log` to return a `KeyValue` for an empty value. (#5076)

View File

@ -29,6 +29,28 @@ type Logger interface {
// Implementations of this method need to be safe for a user to call
// concurrently.
Emit(ctx context.Context, record Record)
// Enabled returns whether the Logger emits for the given context and
// record.
//
// The passed record is likely to be a partial record with only the
// bridge-relevant information being provided (e.g a record with only the
// Severity set). If a Logger 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 Logger will emit for the
// provided context and record, 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 record should not be held by the implementation. A copy should be
// made if the record 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, record Record) bool
}
// LoggerOption applies configuration options to a [Logger].

View File

@ -45,3 +45,6 @@ type Logger struct{ embedded.Logger }
// Emit does nothing.
func (Logger) Emit(context.Context, log.Record) {}
// Enabled returns false. No log records are ever emitted.
func (Logger) Enabled(context.Context, log.Record) bool { return false }

View File

@ -33,6 +33,11 @@ func (b *BatchingProcessor) OnEmit(ctx context.Context, r Record) error {
return nil
}
// Enabled returns true.
func (b *BatchingProcessor) Enabled(context.Context, Record) bool {
return true
}
// Shutdown flushes queued log records and shuts down the decorated expoter.
func (b *BatchingProcessor) Shutdown(ctx context.Context) error {
// TODO (#5063): Implement.

View File

@ -20,3 +20,8 @@ type logger struct {
func (l *logger) Emit(ctx context.Context, r log.Record) {
// TODO (#5061): Implement.
}
func (l *logger) Enabled(ctx context.Context, r log.Record) bool {
// TODO (#5061): Implement.
return true
}

View File

@ -15,6 +15,9 @@ import (
type Processor interface {
// OnEmit is called when a Record is emitted.
//
// OnEmit will be called independent of Enabled. Implementations need to
// validate the arguments themselves before processing.
//
// Implementation should not interrupt the record processing
// if the context is canceled.
//
@ -26,6 +29,24 @@ type Processor interface {
// Before modifying a Record, the implementation must use Record.Clone
// to create a copy that shares no state with the original.
OnEmit(ctx context.Context, record Record) error
// Enabled returns whether the Processor will process for the given context
// and record.
//
// The passed record is likely to be a partial record with only the
// bridge-relevant information being provided (e.g a record with only the
// Severity set). If a Logger 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 record, and will be false if the Processor will not
// process. 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).
//
// Before modifying a Record, the implementation must use Record.Clone
// to create a copy that shares no state with the original.
Enabled(ctx context.Context, record Record) bool
// Shutdown is called when the SDK shuts down. Any cleanup or release of
// resources held by the exporter should be done in this call.
//

View File

@ -35,6 +35,11 @@ func (s *SimpleProcessor) OnEmit(ctx context.Context, r Record) error {
return nil
}
// Enabled returns true.
func (s *SimpleProcessor) Enabled(context.Context, Record) bool {
return true
}
// Shutdown shuts down the expoter.
func (s *SimpleProcessor) Shutdown(ctx context.Context) error {
// TODO (#5062): Implement.