Documentation
¶
Overview ¶
Package tracing is Līdza's OpenTelemetry tracing: opt-in, configured by the standard OTEL_* environment variables, exported over OTLP/HTTP.
With OTEL_EXPORTER_OTLP_ENDPOINT (or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) set, Start installs a tracer provider and the W3C trace context propagator; the framework then records a span per request, database query, job run, mail send, LLM call and outbound HTTP call, carries traceparent across them (into jobs too), and puts trace_id and span_id in the logs. Without it nothing is recorded and the spans cost a no-op call.
Span attributes never hold request bodies, query arguments, headers or message contents: a query's span carries its sqlc name, not its values.
Index ¶
- Constants
- func Enabled() bool
- func End(span trace.Span, err error)
- func Extract(ctx context.Context, h http.Header) context.Context
- func Inject(ctx context.Context, h http.Header)
- func Install(tp trace.TracerProvider) (restore func())
- func LogHandler(h slog.Handler) slog.Handler
- func Middleware() func(http.Handler) http.Handler
- func On() bool
- func Route() func(http.Handler) http.Handler
- func Span(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
- func Start(ctx context.Context, service string) (func(context.Context) error, error)
- func Traceparent(ctx context.Context) string
- func Tracer() trace.Tracer
- func Transport(base http.RoundTripper) http.RoundTripper
- func WithTraceparent(ctx context.Context, tp string) context.Context
Constants ¶
const Instrumentation = "github.com/agim/lidza"
Instrumentation is the tracer name Līdza's spans carry.
Variables ¶
This section is empty.
Functions ¶
func Install ¶
func Install(tp trace.TracerProvider) (restore func())
Install makes tp the provider, with the W3C propagator, until the returned function restores the previous ones: for tests that record spans (go.opentelemetry.io/otel/sdk/trace/tracetest).
func LogHandler ¶
LogHandler adds trace_id and span_id to every record logged with a context that carries a recording span (slog.InfoContext and the like).
func Middleware ¶
Middleware records a server span per request, continuing a traceparent the client sent. Route, next to the router, names it by the matched pattern ("GET /api/v1/posts/{id}"), never by the raw path.
func On ¶
func On() bool
On reports whether spans are being recorded (Start installed a provider); packs skip work that only feeds spans when it is false.
func Route ¶
Route names the request's span by the pattern the router matched; it sits right before the router, where http.Request.Pattern is visible.
func Span ¶
func Span(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)
Span starts a span named name under ctx's: the helper the packs use. End it with End.
func Start ¶
Start installs the tracer provider when Enabled; service names the service unless OTEL_SERVICE_NAME does. The returned function flushes and stops it (bounded by its context); it is a no-op when tracing is off.
func Traceparent ¶
Traceparent is ctx's span as a W3C traceparent value, "" without a recording one: what a job row stores.
func Transport ¶
func Transport(base http.RoundTripper) http.RoundTripper
Transport traces outbound calls: a client span per request, named by method and host, with traceparent sent along.
Types ¶
This section is empty.