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

tracing

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package tracing configures OpenTelemetry trace export and lifecycle helpers. Applications own sampling, attribute classification, collector availability, and telemetry retention.

Index

Constants

This section is empty.

Variables

View Source
var ErrExporterNotConfigured = errors.New("tracing: OTLP exporter endpoint is not configured")

ErrExporterNotConfigured indicates that neither an exporter nor valid endpoint exists.

Functions

func GetTraceID

func GetTraceID(c *gpp.Context) string

GetTraceID extracts the standards-compliant active OpenTelemetry trace ID.

func Middleware

func Middleware() gpp.HandlerFunc

Middleware instruments requests with the process-wide OpenTelemetry provider. Prefer Provider.Middleware when this package owns exporter configuration.

Types

type Config

type Config struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	Endpoint       string
	Headers        map[string]string
	Insecure       bool
	SampleRatio    float64
	BatchTimeout   time.Duration
	ExportTimeout  time.Duration
	Exporter       sdktrace.SpanExporter
	Propagator     propagation.TextMapPropagator
}

Config defines service identity, export transport, sampling, and batching.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider owns the OpenTelemetry SDK lifecycle. Applications should call Shutdown during graceful termination to flush queued spans.

func NewProvider

func NewProvider(ctx context.Context, config Config) (*Provider, error)

NewProvider validates configuration and constructs an owned OpenTelemetry provider.

func (*Provider) ForceFlush

func (provider *Provider) ForceFlush(ctx context.Context) error

ForceFlush exports queued spans within ctx.

func (*Provider) Inject

func (provider *Provider) Inject(ctx context.Context, header http.Header)

Inject writes W3C trace context and baggage headers for an outgoing request.

func (*Provider) Middleware

func (provider *Provider) Middleware() gpp.HandlerFunc

Middleware instruments requests using this provider and its propagator.

func (*Provider) Shutdown

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

Shutdown flushes and releases the owned trace provider.

Jump to

Keyboard shortcuts

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