tracing

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 18 Imported by: 0

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 ParentContext added in v0.2.14

func ParentContext(ctx context.Context, cfg *config.TracingConfig) context.Context

ParentContext returns a context carrying the W3C remote parent span context from the configured traceId and spanId (spec §4.1.3.6). Exported for use at startup to build the root span's parent context.

func Tracer

func Tracer() trace.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

func InitProvider(ctx context.Context, cfg *config.TracingConfig) (*Provider, error)

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.

func (*Provider) Shutdown

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

Shutdown flushes and shuts down the tracer provider. For noop providers this is a no-op. Must be called on application exit.

func (*Provider) Tracer

func (p *Provider) Tracer() trace.Tracer

Tracer returns the tracer for the MCP gateway instrumentation scope.

Jump to

Keyboard shortcuts

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