Commit 1bae687
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.11 parent f3d0394 commit 1bae687
File tree
38 files changed
+4663
-1090
lines changed- .github/workflows
- instrumentation-genai
- opentelemetry-instrumentation-mcp
- examples/simple-client-server
- client
- server
- mcp_simple_tool
- src/opentelemetry/instrumentation/mcp
- tests
- scripts
38 files changed
+4663
-1090
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
92 | 111 | | |
93 | 112 | | |
94 | 113 | | |
| |||
0 commit comments