Skip to content

Add OpenTelemetry metrics to vMCP server #2849

Closed

Description

@JAORMX

Summary

Instrument the vMCP server with OpenTelemetry metrics to enable observability and monitoring of virtual MCP server deployments.

Background

ToolHive already has a comprehensive telemetry package (pkg/telemetry/) that provides:

  • Distributed tracing with W3C Trace Context propagation
  • Prometheus metrics export
  • OTLP support for remote collectors
  • HTTP middleware for automatic instrumentation

The vMCP server currently lacks this instrumentation, making it difficult to monitor and debug production deployments.

Reusable Components

Component Location Description
Telemetry Middleware pkg/telemetry/middleware.go HTTP instrumentation
Config pkg/telemetry/config.go Configuration model
Providers pkg/telemetry/providers/ OTEL provider setup

Existing Metrics (from pkg/telemetry/middleware.go)

toolhive_mcp_requests_total      // Total requests by method, status, MCP method, server, transport
toolhive_mcp_request_duration_seconds  // Request latency histogram
toolhive_mcp_active_connections  // Active connections gauge
toolhive_mcp_tool_calls_total    // Tool-specific call counts

Implementation

  1. Add telemetry middleware to vMCP server (pkg/vmcp/server/server.go)

    • Wrap HTTP routes with telemetry.HTTPMiddleware
    • Configure service name as toolhive-vmcp
  2. Add vMCP-specific metrics

    toolhive_vmcp_backend_requests_total     // Requests per backend
    toolhive_vmcp_backend_latency_seconds    // Per-backend latency
    toolhive_vmcp_composite_tool_duration_seconds  // Composite workflow execution time
    toolhive_vmcp_backends_discovered        // Gauge of active backends
  3. Add configuration support

    • CRD: Add telemetry config to VirtualMCPServerSpec
    • CLI: Add telemetry flags to vmcp serve command
  4. Expose /metrics endpoint

    • Prometheus scrape endpoint for metrics collection

Acceptance Criteria

  • vMCP server uses existing telemetry middleware
  • Prometheus metrics exported at /metrics endpoint
  • Per-backend request metrics tracked
  • Composite tool execution metrics tracked
  • Telemetry configurable via CRD and CLI
  • Sensitive data (tokens, secrets) redacted from traces
  • Unit tests for metrics emission
  • Documentation updated

Activity

  1. added
    enhancement
    vmcp
    on Dec 2, 2025
  2. added
    go
    kubernetes
    api
    on Dec 2, 2025
  3. self-assigned this
    on Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apienhancementgokubernetestelemetryvmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions