Skip to content

Commit 2486d29

Browse files
committed
feat: implement comprehensive OpenTelemetry integration for MCP proxies
- Add complete OpenTelemetry instrumentation with OTLP and Prometheus exporters - Implement HTTP middleware with MCP protocol-aware tracing and metrics - Add CLI flags for telemetry configuration (--otel-endpoint, --otel-metrics-port, etc.) - Expose /metrics endpoints on both HTTPSSEProxy and TransparentProxy - Include comprehensive observability documentation - Support dual export architecture (OTLP push + Prometheus pull) - Add tool-specific metrics and argument sanitization for security - Integrate seamlessly with existing middleware chain Implements: #597 Fixes: #474 Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 5a40447 commit 2486d29

24 files changed

+3619
-113
lines changed

cmd/thv/app/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func proxyCmdFunc(cmd *cobra.Command, args []string) error {
213213
port, proxyTargetURI)
214214

215215
// Create the transparent proxy with middlewares
216-
proxy := transparent.NewTransparentProxy(proxyHost, port, serverName, proxyTargetURI, middlewares...)
216+
proxy := transparent.NewTransparentProxy(proxyHost, port, serverName, proxyTargetURI, nil, middlewares...)
217217
if err := proxy.Start(ctx); err != nil {
218218
return fmt.Errorf("failed to start proxy: %v", err)
219219
}

cmd/thv/app/run.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ var (
8686
runK8sPodPatch string
8787
runCACertPath string
8888
runVerifyImage string
89+
90+
// OpenTelemetry flags
91+
runOtelEndpoint string
92+
runOtelServiceName string
93+
runOtelSamplingRate float64
94+
runOtelHeaders []string
95+
runOtelInsecure bool
96+
runOtelEnablePrometheusMetricsPath bool
8997
)
9098

9199
func init() {
@@ -170,6 +178,20 @@ func init() {
170178

171179
// Add OIDC validation flags
172180
AddOIDCFlags(runCmd)
181+
182+
// Add OpenTelemetry flags
183+
runCmd.Flags().StringVar(&runOtelEndpoint, "otel-endpoint", "",
184+
"OpenTelemetry OTLP endpoint URL (e.g., https://api.honeycomb.io)")
185+
runCmd.Flags().StringVar(&runOtelServiceName, "otel-service-name", "",
186+
"OpenTelemetry service name (defaults to toolhive-mcp-proxy)")
187+
runCmd.Flags().Float64Var(&runOtelSamplingRate, "otel-sampling-rate", 0.1,
188+
"OpenTelemetry trace sampling rate (0.0-1.0)")
189+
runCmd.Flags().StringArrayVar(&runOtelHeaders, "otel-headers", nil,
190+
"OpenTelemetry OTLP headers in key=value format (e.g., x-honeycomb-team=your-api-key)")
191+
runCmd.Flags().BoolVar(&runOtelInsecure, "otel-insecure", false,
192+
"Disable TLS verification for OpenTelemetry endpoint")
193+
runCmd.Flags().BoolVar(&runOtelEnablePrometheusMetricsPath, "otel-enable-prometheus-metrics-path", false,
194+
"Enable Prometheus-style /metrics endpoint on the main transport port")
173195
}
174196

175197
func runCmdFunc(cmd *cobra.Command, args []string) error {
@@ -224,6 +246,12 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
224246
oidcAudience,
225247
oidcJwksURL,
226248
oidcClientID,
249+
runOtelEndpoint,
250+
runOtelServiceName,
251+
runOtelSamplingRate,
252+
runOtelHeaders,
253+
runOtelInsecure,
254+
runOtelEnablePrometheusMetricsPath,
227255
)
228256

229257
// Set the Kubernetes pod template patch if provided

docs/cli/thv_run.md

Lines changed: 27 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)