-
Notifications
You must be signed in to change notification settings - Fork 26
[feat] Contribute mcp Instrumentor #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 22 commits
d8a0ee3
19b25ce
b2bad7c
49649e7
442a45a
10d91ac
0e6e339
6a5f9d6
db1af61
a6ba4c4
4ea1757
3f576c2
f54609e
f8e7172
1a9ce26
fb9d1c7
7b9a8f4
de0ec1d
43526f6
bd28ccc
70b0da3
5f4f773
0af52d9
0d10a82
775f0b1
141f93c
176fd90
0ea9695
e6c479e
1f4f476
8621644
c78df18
5f70570
064c71c
c97c8df
dc2c730
76c2405
323b87a
3902c60
51aaba9
9c0e57a
dc91c62
d7666ca
aab4e7d
5c1aeec
de1020e
5a3437f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# MCP Instrumentor | ||
|
||
OpenTelemetry instrumentation for Model Context Protocol (MCP). | ||
|
||
## Installation | ||
|
||
Included in AWS OpenTelemetry Distro: | ||
|
||
```bash | ||
pip install aws-opentelemetry-distro | ||
``` | ||
|
||
## Usage | ||
|
||
Automatically enabled with: | ||
|
||
```bash | ||
opentelemetry-instrument python your_mcp_app.py | ||
``` | ||
|
||
## Configuration | ||
|
||
- `MCP_INSTRUMENTATION_SERVER_NAME`: Override default server name (default: "mcp server") | ||
|
||
## Spans Created | ||
|
||
- **Client**: | ||
- Initialize: `mcp.initialize` | ||
- List Tools: `mcp.list_tools` | ||
- Call Tool: `mcp.call_tool.{tool_name}` | ||
- **Server**: `tools/initialize`, `tools/list`, `tools/{tool_name}` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,208 @@ | ||||||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||
# SPDX-License-Identifier: Apache-2.0 | ||||||
from typing import Any, Callable, Collection, Dict, Tuple | ||||||
|
||||||
from mcp import ClientRequest | ||||||
|
||||||
from wrapt import register_post_import_hook, wrap_function_wrapper | ||||||
|
||||||
from opentelemetry import trace | ||||||
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor | ||||||
from opentelemetry.instrumentation.utils import unwrap | ||||||
from .semconv import MCPAttributes, MCPSpanNames, MCPOperations, MCPTraceContext, MCPEnvironmentVariables | ||||||
_instruments = ("mcp >= 1.6.0",) | ||||||
|
_instruments = ("mcp >= 1.6.0",) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return _instruments | |
return ("mcp >= 1.6.0",) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be a static method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls other static methods (add_client_attributes and add_server_attributes), so I think keeping _generate_mcp_attributes as an instance method is cleaner. Otherwise, we’d have to call them like MCPInstrumentor.add_client_attributes, which feels less natural in this context. Let me know if I'm wrong. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this doesn't make sense, your code indicates that your instrumentation library instruments mcp >= 1.6.0 but here you have mcp >= 1.1.0. So which is it?
_instruments = ("mcp >= 1.6.0",)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is my mistake. I was able to see that there's no module named "mcp.server.lowlevel" with version 1.1. The minimum version for my instrumentor to be imported is 1.3. However, there's some significant changes to how client message handling is done in the version of 1.6. Explanation from openinference: Arize-ai/openinference#1563 . I will change it to mcp >= 1.6.0. Thank you for pointing it out!