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.0.tar.gz (17.9 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.0.tar.gz.

File metadata

File hashes

Hashes for splunk_otel_instrumentation_fastmcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b2cbf033dc35d878b77e2458aed6536ab2b92e7955a7c4ee37bc3d3426b51f6
MD5 77931fb88ac13b5e33dba8c22d66c131
BLAKE2b-256 18ce82da5874c735ff52754bc81537f0420e7c8c7954cad29df862d080715d30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for splunk_otel_instrumentation_fastmcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fa0655df33854a461b7c5c201afa4c0885dc3bc8d14d397acfe757152d10433
MD5 691c864b29b8dd2b044ac8a078a2857c
BLAKE2b-256 505482b5c37e745a5474863b2b9ffb71e7287b60256f672ac7b33bc9e5688205

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