fastmcp.telemetry
OpenTelemetry instrumentation for FastMCP.
This module provides native OpenTelemetry integration for FastMCP servers and clients.
It uses only the opentelemetry-api package, so telemetry is a no-op unless the user
installs an OpenTelemetry SDK and configures exporters.
Example usage with SDK:
Functions
get_tracer
version: Optional version string for the instrumentation
- A tracer instance. Returns a no-op tracer if no SDK is configured.
inject_trace_context
meta: Optional existing meta dict to merge with trace context
- A new dict containing the original meta (if any) plus trace context keys,
- or None if no trace context to inject and meta was None
record_span_error
extract_trace_context
meta: The meta dict from an MCP request (ctx.request_context.meta)
- An OpenTelemetry Context with the extracted trace context,
- or the current context if no trace context found or already in a trace

