Skip to main content

Splunk OpenTelemetry instrumentation for FastMCP (Model Context Protocol)

Project description

pypi

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

splunk_otel_instrumentation_fastmcp-0.1.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file splunk_otel_instrumentation_fastmcp-0.1.1.tar.gz.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_fastmcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 54d1d4f005b6c7903375335c2afe4e58d33886a036c47682fec2de8fcb84c620
MD5 012f14468e29edbd3f5789fbecc696a6
BLAKE2b-256 6b91ba03da54ed2708fa586307229474a8fd93a3ddb80febbcee1b7986b3d92d

See more details on using hashes here.

File details

Details for the file splunk_otel_instrumentation_fastmcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_fastmcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab520caacb9bce7b6f5a1d305d94d950337793deb7ed33c7b998c91963a26b15
MD5 bda2b4f1e0ab60efd80d00d0ac5bb116
BLAKE2b-256 ec346bed3dfa0e5a587fc508e87088951ee32c49548b21af4853c6f5b84a5e9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page