Documentation
¶
Overview ¶
Package tracing provides OpenTelemetry OTLP trace export for the MCP Gateway. This file provides HTTP handler wrapping helpers.
Package tracing provides OpenTelemetry OTLP trace export for the MCP Gateway.
When an OTLP endpoint is configured (via config or OTEL_EXPORTER_OTLP_ENDPOINT), this package initializes a real tracer provider that exports spans over HTTP. When no endpoint is configured, a noop tracer provider is used, adding zero overhead.
Usage:
tp, err := tracing.InitProvider(ctx, cfg.Gateway.Tracing)
if err != nil {
return err
}
defer tp.Shutdown(ctx)
Once initialized, obtain a tracer with:
tracer := otel.Tracer("github.com/github/gh-aw-mcpg")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Tracer ¶
Tracer returns the global MCP gateway tracer. This is a convenience wrapper around otel.Tracer for packages that don't hold a reference to the Provider.
func WrapHTTPHandler ¶
func WrapHTTPHandler(next http.Handler, spanName string, extraAttrs ...attribute.KeyValue) http.Handler
WrapHTTPHandler wraps an http.Handler with an OpenTelemetry server span. A span named spanName is created for every request, with http.method and http.path set automatically. Extra attrs are merged in.
Incoming W3C traceparent/tracestate headers are extracted so that an agent-originated trace is continued; if no such headers are present a fresh root span (and new trace ID) is created automatically.
This is a low-level helper used by both the MCP gateway middleware and the GitHub API proxy. Callers that need session-level attributes (e.g. session.id) should add them as extra attrs or extend the context themselves.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider wraps an OpenTelemetry TracerProvider and provides a Shutdown method.
func InitProvider ¶
InitProvider initializes the global OpenTelemetry tracer provider. When endpoint is empty, a noop provider is installed (zero overhead). When endpoint is configured, an OTLP/HTTP exporter is created and the SDK tracer provider is registered as the global provider.
In both cases a W3C TraceContext propagator is registered globally so that incoming traceparent/tracestate headers are honoured by all HTTP middleware.
The returned Provider must be shut down on application exit to flush buffered spans.