Skip to main content
TelemetryManager is the implementation behind the ObservabilityInstance you get back from instrumentServer. Most users never construct one directly — instrumentServer does it for you. Reach for it when you want more control: multiple managers per process, advanced testing, or non-MCP instrumentation.

Constructor

Validates the config, builds the OpenTelemetry NodeSDK, attaches resource detectors, and starts the SDK.

Public properties

Tracer
The OpenTelemetry tracer scoped to your serverName / serverVersion.
Meter
The OpenTelemetry meter scoped to your serverName / serverVersion.

Methods

startActiveSpan(name, attributes, fn)

Open an active span. Adds mcp.session.id to the attributes automatically.

createSpan(name, attributes)

Create a span without making it active. Useful when you need a manually managed span.

getHistogram(name, options)

Returns a recorder function (value, attributes?) => void. Reuse the same recorder across calls to avoid re-creating the instrument:

getIncrementCounter(name, options)

Returns an increment function (value, attributes?) => void:

getArgumentAttributes(params, prefix?)

Flattens an object of tool arguments into a flat attribute map for use in span attributes. Honors enableArgumentCollection — returns {} when off.

processTelemetryAttributes(data)

Runs data through every configured dataProcessor in order.

shutdown(): Promise<void>

Records the session-duration histogram and shuts down the underlying NodeSDK. Always call this on graceful exit.

Example: standalone use

See also

instrumentServer

Higher-level entry point most users want.

Custom instrumentation

Patterns for using the tracer and meter directly.