otel

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package otel contains options for including OpenTelemetry baggage and tracing in logging records.

Placing the options in a separate package minimizes the dependencies pulled in by those who do not need OpenTelemetry tracing.

Index

Constants

View Source
const (
	// OtelBaggageKey is the prefix for keys obtained from the OpenTelemetry
	// Baggage to mitigate collision with other log attributes.
	OtelBaggageKey = "otel-baggage/"
)

noinspection GoNameStartsWithPackageName.

Variables

This section is empty.

Functions

func MustParse added in v0.11.0

func MustParse(bStr string) baggage.Baggage

MustParse wraps baggage.Parse to alleviate needless error checking when it's known, a priori, that an error can never happen.

func WithOtelBaggage added in v0.11.0

func WithOtelBaggage() options.OptionProcessor

WithOtelBaggage returns a gslog option that directs that the slog.Handler to include OpenTelemetry baggage. The baggage.Baggage is obtained from the context, if available, and added as attributes.

The baggage keys are prefixed with "otel-baggage/" to mitigate collision with other log attributes. Baggage that have no properties are mapped to a slog.Attr for a string value. Baggage that have properties mapped to a slog.Group with two keys, "value" which is the value of the baggage, and "properties" which is the properties of the baggage as a slog.Group. Baggage properties that have no value are mapped to slog.Any with a nil value.

Baggage mapped attributes take precedence over any preexisting attributes that a handler or logging record may already have.

For example, "a=one,b=two;p1;p2=val2" would map to

slog.String("otel-baggage/a", "one")
slog.Group("otel-baggage/b",
	slog.String("value", "two"),
	slog.Group("properties",
		slog.Any("p1", nil),
		slog.String("p2", "val2"),
	),
)

func WithOtelTracing

func WithOtelTracing(projectID string) options.OptionProcessor

WithOtelTracing returns an option that directs that the slog.Handler to include OpenTelemetry tracing. Tracing information is obtained from the trace.SpanContext stored in the context, if provided.

Types

This section is empty.

Jump to

Keyboard shortcuts

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