Help us shape the future of Go! Take the 2026 Go Developer Survey

tracing

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 18 Imported by: 0

README

Tracing

Open(ctx, Config, logger) acquires an owned provider and its bounded batch worker. Disabled configuration returns a no-op provider without an export worker. Borrow its native TracerProvider for instrumentation; call Shutdown(ctx) after all producers stop. Setup does not contact the collector. No process-global provider is installed. The package does not import application configuration; the official OTLP HTTP exporter can read its standard TLS settings.

The batch queue is bounded and non-blocking; export is best-effort. Failed batches are reported via the borrowed logger without raw endpoint/error/span data and are not returned to OpenTelemetry's global error handler. Shutdown errors concern the shutdown operation, not a guarantee of successful delivery. Logger lifetime must exceed provider lifetime. See observability for configuration, limits, examples, and the phased integration plan.

Outgoing HTTP

NewHTTPTransport(base, tracer) borrows a transport and non-nil native tracer. Nil base uses http.DefaultTransport. It clones requests, injects W3C trace context and removes baggage from the outgoing copy. Choose destinations and redirect policy explicitly. No global client is changed. Spans end at response headers; bodies and errors remain unchanged. CloseIdleConnections forwards to the borrowed transport when supported. See examples and limits.

Documentation

Overview

Package tracing constructs an explicitly owned OpenTelemetry provider. It does not install process-global providers or read application configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPTransport

func NewHTTPTransport(base http.RoundTripper, tracer trace.Tracer) http.RoundTripper

NewHTTPTransport wraps a borrowed transport for a deliberately chosen integration. It injects W3C trace context, never baggage. Use only for destinations allowed to receive trace metadata. Spans end on response headers, not body consumption. URLs, headers, bodies and raw errors are never recorded. Nil base uses DefaultTransport. The tracer must be non-nil. The caller owns connection cleanup and client timeouts/redirect policy.

Types

type Config

type Config struct {
	Enabled         bool
	ServiceName     string
	Endpoint        string
	SampleRatio     float64
	ExportTimeout   time.Duration
	ShutdownTimeout time.Duration
}

Config selects optional tracing. A disabled zero value is valid. Endpoint is the full OTLP HTTP URL, including /v1/traces. Credentials in URLs are rejected; use a local collector to handle backend authentication.

func (Config) Validate

func (c Config) Validate() error

type Provider

type Provider struct {
	trace.TracerProvider
	// contains filtered or unexported fields
}

Provider owns the exporter and its bounded batch worker. Borrow TracerProvider for instrumentation; stop all producers before Shutdown. Concurrent use is safe.

func Open

func Open(ctx context.Context, cfg Config, logger *slog.Logger) (*Provider, error)

Open acquires an exporter and starts its bounded batch worker. It does not contact the collector during setup. The caller owns Shutdown after all producers stop. Disabled tracing owns no worker; invalid settings fail before resource setup. Export outages lose telemetry, not application work; failed batches are reported through the borrowed logger without endpoint URLs, response bodies, or span data.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown flushes queued spans within the smaller of the caller's deadline and the configured budget. It is idempotent. Success does not guarantee delivery: export failures are reported via logging, and a full queue drops new spans.

Jump to

Keyboard shortcuts

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