otel

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 13 Imported by: 1

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

View Source
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.

func New

func New(handler slog.Handler, opts ...Option) Handler

New creates a new Handler with the given Option(s).

func (Handler) Enabled

func (h Handler) Enabled(ctx context.Context, level slog.Level) bool

func (Handler) Handle

func (h Handler) Handle(ctx context.Context, record slog.Record) error

func (Handler) WithAttrs

func (h Handler) WithAttrs(attrs []slog.Attr) slog.Handler

func (Handler) WithGroup

func (h Handler) WithGroup(name string) slog.Handler

type Option

type Option func(*options)

Option configures the Handler with specific options.

func WithRecordEvent

func WithRecordEvent(passThrough bool) Option

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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL