tracing

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package tracing provides OpenTelemetry tracing initialization and helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTraceContext

func ExtractTraceContext(
	ctx context.Context,
	data map[string]interface{},
) context.Context

ExtractTraceContext extracts trace context from a data map and returns a new context with the extracted span context. If no trace context is present, the original context is returned.

func ExtractTraceContextFromHeader

func ExtractTraceContextFromHeader(
	ctx context.Context,
	header http.Header,
) context.Context

ExtractTraceContextFromHeader extracts trace context from HTTP-compatible headers and returns a new context. If no trace context is present, the original context is returned.

Header keys are normalized to canonical MIME format before extraction. Some transports (e.g., NATS JetStream) deliver headers with non-canonical casing (lowercase "traceparent" instead of "Traceparent"), which breaks http.Header.Get lookups. Normalizing ensures reliable extraction.

func InitTracer

func InitTracer(
	ctx context.Context,
	serviceName string,
	cfg config.TracingConfig,
) (func(context.Context) error, error)

InitTracer initializes the OpenTelemetry tracer provider. It always sets the global W3C TraceContext propagator. When tracing is disabled, a noop provider is used. Returns a shutdown function that must be called on exit.

func NewTraceHandler

func NewTraceHandler(
	inner slog.Handler,
) slog.Handler

NewTraceHandler creates a slog.Handler that adds trace_id and span_id attributes from the context's span, delegating to the inner handler.

Types

This section is empty.

Jump to

Keyboard shortcuts

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