cetra reads the spans that the MCP Python SDK writes for each request, with a server’s tool call as a tool span that joins the client’s trace.
Install
Section titled “Install”Install MCP 2.x, the OpenTelemetry SDK and its OTLP exporter. The fixture was captured with MCP 2.3.0.
pip install "mcp>=2" opentelemetry-sdk opentelemetry-exporter-otlp-proto-httpSet up
Section titled “Set up”The MCP SDK creates spans through the global tracer provider. Each process that runs a client or a server sets its own provider, so each one exports its own spans. The client and the server in the fixture ran in separate processes.
Set the exporter variables for each process:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <SK_CETRA_KEY>"Replace <SK_CETRA_KEY> with your sk-cetra-… API key. See Send OpenTelemetry.
from mcp.server.mcpserver import MCPServerfrom opentelemetry import tracefrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor
provider = TracerProvider()provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))trace.set_tracer_provider(provider)
server = MCPServer("weather")
@server.tool()def get_weather(city: str) -> str: """Look up the weather for a city.""" return f'{{"temperature_c": 18, "conditions": "sunny", "city": "{city}"}}'
if __name__ == "__main__": server.run("stdio")import asyncioimport osimport sys
from mcp import Clientfrom mcp.client.stdio import StdioServerParametersfrom opentelemetry import tracefrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor
provider = TracerProvider()provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter()))trace.set_tracer_provider(provider)
params = StdioServerParameters( command=sys.executable, args=["server.py"], # The stdio transport starts the server with only the environment given here. env={k: v for k, v in os.environ.items() if k in ("PATH", "HOME") or k.startswith("OTEL_")},)
async def main() -> None: async with Client(params) as client: await client.call_tool("get_weather", {"city": "Paris"}) provider.force_flush()
asyncio.run(main())The server exports each span as it ends, so its spans arrive even when the client closes it first. Use a span processor that exports at once, as the samples do.
import cetra
cetra.init(instrument=["mcp"])The mcp instrument in cetra-sdk installs with pip install "cetra-sdk[mcp]". It uses OpenInference’s MCP instrumentation, openinference-instrumentation-mcp 2.1.5. It creates no spans. It carries the trace context to the server, so spans that the server process makes, with its own instrumentation or with spans you write, join the client’s trace. On mcp<2 the MCP SDK makes no spans itself. On mcp>=2 the SDK passes the context itself, and the instrument is not needed. In a spike with mcp>=2 the instrument logged a harmless ValueError and had no effect. No fixture backs the instrument: the fixture above was captured without it.
What you get
Section titled “What you get”One call_tool makes a trace with two spans that share it:
- a
spanfor the client’s send,MCP send tools/call get_weather; - a
toolspan for the server’stools/call get_weather, a child of the client’s span, with the tool’s name and the operationexecute_tool.
The scenario also lists the tools, so the fixture has more spans. Each request is a trace of its own. The SDK sends more requests than the scenario makes: server/discover and a second tools/list. Each of them is a span on both sides.
Limits
Section titled “Limits”- The SDK records no arguments and no results. The spans have no input and no output, so the tool’s content is not in cetra.
- The
mcpinstrument creates no spans, and it is not needed on MCP 2.x. On MCP 1.x there are no MCP spans at all. - Each process exports its own spans, so a server process needs its own provider.
- The fixture was captured with MCP 2.3.0 over stdio. Streamable HTTP and the other transports were not captured.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Send OpenTelemetry: the endpoint and the headers cetra expects.