fastmcp.server.telemetry
Server-side telemetry helpers.
Functions
get_auth_span_attributes
get_session_span_attributes
get_protocol_span_attributes
mcp.protocol.version attribute the SDK’s own
OpenTelemetryMiddleware sets — FastMCP drops that middleware to avoid a
duplicate SERVER span, so this restores the attribute on FastMCP’s span.
record_span_exception
seam_span
mcp.method.name, fastmcp.server.name, auth/session context) so
seam-only methods (logging/setLevel, tasks/*, ping, initialize, …)
are fully attributed even though they never reach the high-level path. It is
marked with SEAM_SPAN_MARKER so a later server_span call in the
high-level path enriches this span with component attributes instead of
opening a second one. Exceptions raised anywhere below the seam — including
rejections before the high-level path (auth, not-found, middleware vetoes)
that would otherwise produce no SERVER span at all — are recorded here.
In propagation_only mode no span is opened at all — this is the one place
that has to know the difference, because the seam is where the incoming
_meta parent context is applied for the whole request.
server_span
FastMCPServerMiddleware and marked with SEAM_SPAN_MARKER), this sets the
component attributes on that span and yields it without starting a second
span — so failures rejected before this point and the successful high-level
call share one richly-attributed SERVER span. Otherwise (non-seam contexts,
e.g. in-process mcp.call_tool() calls that bypass the dispatcher) it opens a
new SERVER span as before.
Automatically records any exception on the span and sets error status.
In propagation_only mode no span is opened or enriched. The seam has
normally already attached the incoming parent context for this request;
doing it again here is a no-op, and covers the in-process callers that
bypass the dispatcher and so never reach the seam at all.

