Documentation
¶
Index ¶
- func HTTPHandler(tracer trace.Tracer) func(http.Handler) http.Handler
- func HTTPHandlerFunc(tracer trace.Tracer) func(http.HandlerFunc) http.HandlerFunc
- func NewProvider(endpoint, header, name string, attrs ...Attr) (*sdktrace.TracerProvider, error)
- func RedactedURL(u *url.URL) string
- func ShutdownProvider(ctx context.Context) error
- func StartHTTPClientSpan(tracer trace.Tracer, req *http.Request) (*http.Request, func(*http.Response, error))
- func StartSpan(tracer trace.Tracer, ctx context.Context, name string, ...) (context.Context, func(error))
- type Attr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPHandler ¶
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 ¶
RedactedURL returns the URL with password redacted
func ShutdownProvider ¶ added in v1.4.0
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) }()