otel

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 18 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPHandler

func HTTPHandler(tracer trace.Tracer) func(http.Handler) http.Handler

HTTPHandler returns an HTTP middleware that creates OpenTelemetry spans for incoming requests. It extracts trace context from request headers to support distributed tracing, records the HTTP method, URL, and status code, and marks spans as errors for 4xx/5xx responses.

func HTTPHandlerFunc

func HTTPHandlerFunc(tracer trace.Tracer) func(http.HandlerFunc) http.HandlerFunc

HTTPHandlerFunc is like HTTPHandler but wraps http.HandlerFunc directly. This is useful for routers that use HandlerFunc.

func NewProvider

func NewProvider(endpoint, header, name string, attrs ...Attr) (*sdktrace.TracerProvider, error)

NewProvider creates a new OpenTelemetry tracer provider. It expects a endpoint formatted as host:port for HTTPS endpoints, or a URL with a http, https, grpc or grpcs scheme, host, port and optional path.

func RedactedURL

func RedactedURL(u *url.URL) string

RedactedURL returns the URL with password redacted

func ShutdownProvider added in v1.4.0

func ShutdownProvider(ctx context.Context) error

ShutdownProvider shuts down the global tracer provider, flushing and exporting any remaining spans. After this call, NewProvider can be used again. It is a no-op if no provider has been registered.

The OpenTelemetry global provider is reset to a no-op provider so that any instrumentation that calls otel.GetTracerProvider() after shutdown receives a safe, inert implementation rather than a shut-down SDK provider.

func StartHTTPClientSpan

func StartHTTPClientSpan(tracer trace.Tracer, req *http.Request) (*http.Request, func(*http.Response, error))

StartHTTPClientSpan starts a span for an outgoing HTTP client request. It injects trace context into request headers for distributed tracing. Returns the modified request (with trace context in headers) and a finish function to call after receiving the response.

Usage:

req, finishSpan := otel.StartHTTPClientSpan(tracer, req)
resp, err := client.Do(req)
finishSpan(resp, err)

func StartSpan

func StartSpan(tracer trace.Tracer, ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, func(error))

StartSpan starts a new OTEL span with the given name and optional attributes. Returns the context (with span) and an end function that records any error and ends the span. If tracer is nil, returns the original context and a no-op.

Usage:

ctx, endSpan := otel.StartSpan(tracer, ctx, "MyOperation", attribute.String("key", "value"))
defer func() { endSpan(err) }()

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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