telemetry

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package telemetry provides OpenTelemetry instrumentation for ToolHive MCP server proxies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPMiddleware

func NewHTTPMiddleware(
	config Config,
	tracerProvider trace.TracerProvider,
	meterProvider metric.MeterProvider,
	serverName, transport string,
) types.Middleware

NewHTTPMiddleware creates a new HTTP middleware for OpenTelemetry instrumentation. serverName is the name of the MCP server (e.g., "github", "fetch") transport is the backend transport type ("stdio" or "sse")

Types

type Config

type Config struct {
	// Endpoint is the OTLP endpoint URL
	Endpoint string

	// ServiceName is the service name for telemetry
	ServiceName string

	// ServiceVersion is the service version for telemetry
	ServiceVersion string

	// SamplingRate is the trace sampling rate (0.0-1.0)
	SamplingRate float64

	// Headers contains authentication headers for the OTLP endpoint
	Headers map[string]string

	// Insecure indicates whether to disable TLS verification
	Insecure bool

	// EnablePrometheusMetricsPath controls whether to expose Prometheus-style /metrics endpoint
	// The metrics are served on the main transport port at /metrics
	// This is separate from OTLP metrics which are sent to the Endpoint
	EnablePrometheusMetricsPath bool

	// EnvironmentVariables is a list of environment variable names that should be
	// included in telemetry spans as attributes. Only variables in this list will
	// be read from the host machine and included in spans for observability.
	// Example: []string{"NODE_ENV", "DEPLOYMENT_ENV", "SERVICE_VERSION"}
	EnvironmentVariables []string
}

Config holds the configuration for OpenTelemetry instrumentation.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default telemetry configuration.

type HTTPMiddleware

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

HTTPMiddleware provides OpenTelemetry instrumentation for HTTP requests.

func (*HTTPMiddleware) Handler

func (m *HTTPMiddleware) Handler(next http.Handler) http.Handler

Handler implements the middleware function that wraps HTTP handlers. This middleware should be placed after the MCP parsing middleware in the chain to leverage the parsed MCP data.

type Provider

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

Provider encapsulates OpenTelemetry providers and configuration.

func NewProvider

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

NewProvider creates a new OpenTelemetry provider with the given configuration.

func (*Provider) MeterProvider

func (p *Provider) MeterProvider() metric.MeterProvider

MeterProvider returns the configured meter provider.

func (*Provider) Middleware

func (p *Provider) Middleware(serverName, transport string) types.Middleware

Middleware returns an HTTP middleware that instruments requests with OpenTelemetry. serverName is the name of the MCP server (e.g., "github", "fetch") transport is the backend transport type ("stdio" or "sse")

func (*Provider) PrometheusHandler

func (p *Provider) PrometheusHandler() http.Handler

PrometheusHandler returns the Prometheus metrics handler if configured. Returns nil if no metrics port is configured.

func (*Provider) Shutdown

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

Shutdown gracefully shuts down the telemetry provider.

func (*Provider) TracerProvider

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

TracerProvider returns the configured tracer provider.

Jump to

Keyboard shortcuts

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