TelemetryManager, wires up the OpenTelemetry Node SDK, then
calls McpServerInstrumentation.instrument() to patch
server.registerTool so every subsequent tool registration produces spans
and metrics automatically.
Parameters
McpServer
required
An instance of
McpServer from @modelcontextprotocol/sdk/server/mcp.
Must be passed before any tools are registered (instrumentation only
applies to tools registered after this call).TelemetryConfig
required
Configuration for the telemetry pipeline. See the
TelemetryConfig reference for
every field.Returns
ObservabilityInstance
An object with helpers for custom instrumentation and shutdown:
startActiveSpan(name, attributes, fn)getHistogram(name, options)getIncrementCounter(name, options)processTelemetryAttributes(data)shutdown(): Promise<void>
ObservabilityInstance.Example
Side effects
CallinginstrumentServer does several things at once:
- Validates the config via
ConfigValidator.validate(config). Throws on invalid input (missing endpoint, bad sampling rate, malformed auth). - Stores the API key for the safety-check API. The token from
exporterAuth.apiKeyorexporterAuth.tokenis forwarded. - Starts the OpenTelemetry Node SDK with trace + metric exporters, sampler, and resource detectors.
- Patches
server.registerToolto wrap every handler in an instrumented function.
When to call it
Always immediately after constructing theMcpServer, before any
registerTool:
instrumentServer are not instrumented.
Errors
All thrown synchronously at the call site.
See also
TelemetryConfig
Every config field with defaults.
ObservabilityInstance
The object returned by this function.