Documentation ¶
Overview ¶
Package otel provides a handler for correlation between log records and Open Telemetry spans.
It adds [W3C Trace Context] attributes to log records if there is a span in the context, so the logs could be correlated with the spans in the distributed tracing system.
It also records log records as trace span's events if it's enabled.
Index ¶
Constants ¶
const ( // TraceKey is the key used by the [ID of the whole trace] forest and is used to uniquely // identify a distributed trace through a system. It is represented as a 16-byte array, // for example, 4bf92f3577b34da6a3ce929d0e0e4736. // All bytes as zero (00000000000000000000000000000000) is considered an invalid value. // // [ID of the whole trace]: https://www.w3.org/TR/trace-context/#trace-id TraceKey = "trace_id" // SpanKey is the key used by the [ID of this request] as known by the caller. // It is represented as an 8-byte array, for example, 00f067aa0ba902b7. // All bytes as zero (0000000000000000) is considered an invalid value. // // [ID of this request]: https://www.w3.org/TR/trace-context/#parent-id SpanKey = "span_id" // TraceFlagsKey is the key used by an 8-bit field that controls [tracing flags] // such as sampling, trace level, etc. // // [tracing flags]: https://www.w3.org/TR/trace-context/#trace-flags TraceFlagsKey = "trace_flags" )
Keys for W3C Trace Context attributes by following Trace Context in non-OTLP Log Formats.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler correlates log records with Open Telemetry spans.
To create a new Handler, call New.
type Option ¶
type Option func(*options)
Option configures the Handler with specific options.
func WithRecordEvent ¶
WithRecordEvent enables recording log records as trace span's events. If passThrough is true, the log record will pass through to the next handler.
If the level is less than slog.LevelError, the log record will be recorded as an event. Otherwise. the log record will be recorded as an exception event and set the status of span to Error.