tracing

package
v0.1.135 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

View Source
const Instrumentation = "github.com/agim/lidza"

Instrumentation is the tracer name Līdza's spans carry.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled reports whether the environment asks for tracing.

func End

func End(span trace.Span, err error)

End records err (if any) on span and ends it.

func Extract

func Extract(ctx context.Context, h http.Header) context.Context

Extract reads a trace context from h into ctx.

func Inject

func Inject(ctx context.Context, h http.Header)

Inject writes ctx's trace context into a carrier (W3C traceparent).

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

func LogHandler(h slog.Handler) slog.Handler

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

func Middleware() func(http.Handler) http.Handler

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

func Route() func(http.Handler) http.Handler

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

func Start(ctx context.Context, service string) (func(context.Context) error, error)

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

func Traceparent(ctx context.Context) string

Traceparent is ctx's span as a W3C traceparent value, "" without a recording one: what a job row stores.

func Tracer

func Tracer() trace.Tracer

Tracer is Līdza's tracer from the installed provider.

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.

func WithTraceparent

func WithTraceparent(ctx context.Context, tp string) context.Context

WithTraceparent continues the trace a traceparent value names.

Types

This section is empty.

Jump to

Keyboard shortcuts

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