Splunk OpenTelemetry instrumentation for FastMCP (Model Context Protocol)
Project description
This library provides automatic instrumentation for FastMCP, a Python library for building Model Context Protocol (MCP) servers.
Installation
pip install splunk-otel-instrumentation-fastmcp
This can also be installed with the instruments extra to automatically install FastMCP:
pip install 'splunk-otel-instrumentation-fastmcp[instruments]'
Usage
Programmatic instrumentation:
from opentelemetry.instrumentation.fastmcp import FastMCPInstrumentor
FastMCPInstrumentor().instrument()
Auto-instrumentation:
The instrumentation is automatically applied when using OpenTelemetry auto-instrumentation:
opentelemetry-instrument python your_mcp_server.py
Environment Variables
The following environment variables control the instrumentation behavior:
OTEL_INSTRUMENTATION_GENAI_ENABLE: Enable/disable instrumentation (default: true)
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: Capture tool arguments and results (default: false)
OTEL_INSTRUMENTATION_GENAI_EMITTERS: Select emitters - span, metric, event (default: span)
What is Instrumented
Server-side:
FastMCP server initialization
Tool execution via ToolManager.call_tool
Client-side:
FastMCP client session lifecycle
Tool calls and listings
Transport-level:
Automatic trace context propagation via _meta field
Works for all MCP transports: stdio, SSE, streamable-http
Trace Context Propagation
The instrumentation automatically propagates W3C TraceContext (traceparent, tracestate) between MCP client and server processes. This enables distributed tracing across process boundaries:
Client spans and server spans share the same trace_id
Server tool execution spans are children of client tool call spans
No code changes required in your MCP server or client
Telemetry
Spans:
mcp.server - Parent span for server operations
{tool_name}.tool - Child span for each tool execution
mcp.client - Parent span for client session
Metrics:
gen_ai.mcp.tool.duration - Duration of tool executions (histogram)
Events:
When content capture is enabled:
mcp.tool.input - Tool arguments
mcp.tool.output - Tool results
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splunk_otel_instrumentation_fastmcp-0.1.1.tar.gz.
File metadata
- Download URL: splunk_otel_instrumentation_fastmcp-0.1.1.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.3 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54d1d4f005b6c7903375335c2afe4e58d33886a036c47682fec2de8fcb84c620
|
|
| MD5 |
012f14468e29edbd3f5789fbecc696a6
|
|
| BLAKE2b-256 |
6b91ba03da54ed2708fa586307229474a8fd93a3ddb80febbcee1b7986b3d92d
|
File details
Details for the file splunk_otel_instrumentation_fastmcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: splunk_otel_instrumentation_fastmcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.3 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab520caacb9bce7b6f5a1d305d94d950337793deb7ed33c7b998c91963a26b15
|
|
| MD5 |
bda2b4f1e0ab60efd80d00d0ac5bb116
|
|
| BLAKE2b-256 |
ec346bed3dfa0e5a587fc508e87088951ee32c49548b21af4853c6f5b84a5e9b
|