Documentation
¶
Overview ¶
Package tracing builds an OpenTelemetry TracerProvider that batches spans to the exporter in a resolved otelcore.Settings: a collector, a slog logger or a writer. It records no spans itself: install the provider globally and instrumentation such as go/transit's OTel middleware reads it from there.
Index ¶
Constants ¶
const DefaultSampling = 0.1
DefaultSampling is the parent-based ratio applied when none is configured. It is deliberately production-safe: set telemetry.tracing.sampling = 1.0 to record every trace while developing or following the tutorial.
Variables ¶
This section is empty.
Functions ¶
func NewProvider ¶
func NewProvider( ctx context.Context, res *resource.Resource, s otelcore.Settings, opts ...Option, ) (*sdktrace.TracerProvider, error)
NewProvider builds a TracerProvider that batches spans to s.Exporter. A nil s.Exporter means otelcore.Collector{}, which reads the standard OTEL_EXPORTER_OTLP_* environment variables. Sampling is parent-based around a TraceID-ratio sampler, so a sampled trace stays whole across services.
The caller owns the returned provider's Shutdown — typically by registering it on the controls.Controller so spans flush on graceful stop.
Types ¶
type Option ¶
type Option func(*config)
Option configures the tracer provider.
func WithSampling ¶
WithSampling sets the parent-based head sampling ratio (0.0–1.0). Defaults to DefaultSampling.