Skip to content

Commit 1bae687

Browse files
committed
Add OpenTelemetry instrumentation for MCP (Model Context Protocol)
This commit adds automatic instrumentation for the Model Context Protocol, enabling distributed tracing for MCP client and server operations. Key Features: - Automatic tracing for MCP client requests and notifications - Automatic tracing for MCP server request/notification handlers - Distributed trace context propagation via W3C Trace Context - Support for both stdio and HTTP transports - MCP semantic conventions support - Session ID tracking for HTTP transport Implementation: - Instruments BaseSession.send_request/send_notification (client-side) - Instruments Server._handle_request/_handle_notification (server-side) - Injects/extracts trace context via params._meta field - Creates linked spans for distributed tracing Code Quality: - 58 comprehensive unit tests (100% pass rate) - Lint score: 10.00/10 - Passes all pre-commit hooks - Full type annotations and documentation Package: opentelemetry-instrumentation-mcp Location: instrumentation-genai/opentelemetry-instrumentation-mcp/ Dependencies: mcp >= 1.8.1
1 parent f3d0394 commit 1bae687

38 files changed

+4663
-1090
lines changed

.github/workflows/lint_0.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ jobs:
8989
- name: Run tests
9090
run: tox -e lint-instrumentation-google-genai
9191

92+
lint-instrumentation-mcp:
93+
name: instrumentation-mcp
94+
runs-on: ubuntu-latest
95+
timeout-minutes: 30
96+
steps:
97+
- name: Checkout repo @ SHA - ${{ github.sha }}
98+
uses: actions/checkout@v4
99+
100+
- name: Set up Python 3.13
101+
uses: actions/setup-python@v5
102+
with:
103+
python-version: "3.13"
104+
105+
- name: Install tox
106+
run: pip install tox-uv
107+
108+
- name: Run tests
109+
run: tox -e lint-instrumentation-mcp
110+
92111
lint-resource-detector-containerid:
93112
name: resource-detector-containerid
94113
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)