Skip to content

[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

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d8a0ee3
Unit Test and MCP Instrumentor
Johnnyl202 Jul 23, 2025
19b25ce
Merge branch 'main' into MCP-Instrumentor
liustve Jul 23, 2025
b2bad7c
Fix lint errors
Johnnyl202 Jul 23, 2025
49649e7
Testing coverage and dependency issues
Johnnyl202 Jul 24, 2025
442a45a
Code Cleanup and To Test Dependencies
Johnnyl202 Jul 24, 2025
10d91ac
Fixed mcp supported python
Johnnyl202 Jul 24, 2025
0e6e339
Added copywrite headers
Johnnyl202 Jul 24, 2025
6a5f9d6
Testing lint checker
Johnnyl202 Jul 24, 2025
db1af61
Testing lint checker 2
Johnnyl202 Jul 24, 2025
a6ba4c4
Testing lint checker3
Johnnyl202 Jul 25, 2025
4ea1757
Test lint check4
Johnnyl202 Jul 25, 2025
3f576c2
Added input/output types, further code cleanup, got rid of pylint dis…
Johnnyl202 Jul 25, 2025
f54609e
Working Version of Cleaned Up Code
Johnnyl202 Jul 25, 2025
f8e7172
Contract Test
Johnnyl202 Jul 29, 2025
1a9ce26
Restore pyproject.toml file
Johnnyl202 Jul 29, 2025
fb9d1c7
pyproject.toml
Johnnyl202 Jul 29, 2025
7b9a8f4
Update pyproject.toml
Johnnyl202 Jul 29, 2025
de0ec1d
Fixed pyproject.toml for mcpinstrumentor
Johnnyl202 Jul 29, 2025
43526f6
Fixed pyproject.toml for mcpinstrumentor
Johnnyl202 Jul 29, 2025
bd28ccc
adde semconv file, client span name changed, new folder name, mcpinst…
Johnnyl202 Jul 31, 2025
70b0da3
updated instrumentation README.md,revert some changes in distro/pypro…
Johnnyl202 Jul 31, 2025
5f4f773
Merge branch 'main' into MCP-Instrumentor
liustve Aug 1, 2025
0af52d9
Fixed span attributes, updated mcp model, lint, semconv changes
Johnnyl202 Aug 1, 2025
0d10a82
Merge branch 'MCP-Instrumentor' of github.com:JohnnyL202/aws-otel-pyt…
Johnnyl202 Aug 1, 2025
775f0b1
lint and test coverage
Johnnyl202 Aug 2, 2025
141f93c
Merge branch 'main' into MCP-Instrumentor
liustve Aug 2, 2025
176fd90
lint and test coverage
Johnnyl202 Aug 3, 2025
0ea9695
lint and contract test coverage
Johnnyl202 Aug 4, 2025
e6c479e
test coverage and lint
Johnnyl202 Aug 4, 2025
1f4f476
test coverage and lint
Johnnyl202 Aug 4, 2025
8621644
test coverage and lint
Johnnyl202 Aug 4, 2025
c78df18
Merge branch 'main' into MCP-Instrumentor
liustve Aug 5, 2025
5f70570
fixes
liustve Aug 5, 2025
064c71c
add otel propagation library
liustve Aug 6, 2025
c97c8df
Fix MCP instrumentation for distributed tracing
Johnnyl202 Aug 6, 2025
dc2c730
add further tool instrumentation
liustve Aug 6, 2025
76c2405
cleanup code
liustve Aug 7, 2025
323b87a
add more span attribute logic
liustve Aug 7, 2025
3902c60
add span support for notifications
liustve Aug 7, 2025
51aaba9
add support for notifications + refactoring
liustve Aug 7, 2025
9c0e57a
add rpc service name for MCP server
liustve Aug 7, 2025
dc91c62
removed typo
liustve Aug 7, 2025
d7666ca
modify contract tests
liustve Aug 8, 2025
aab4e7d
add session id extraction logic
liustve Aug 10, 2025
5c1aeec
add further trace propagation for responses
liustve Aug 10, 2025
de1020e
Revert "add further trace propagation for responses"
liustve Aug 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aws-opentelemetry-distro/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@ dependencies = [
# If a new patch is added into the list, it must also be added into tox.ini, dev-requirements.txt and _instrumentation_patch
patch = [
"botocore ~= 1.0",
"mcp >= 1.6.0",
]

test = []

[project.entry-points.opentelemetry_configurator]
aws_configurator = "amazon.opentelemetry.distro.aws_opentelemetry_configurator:AwsOpenTelemetryConfigurator"

[project.entry-points.opentelemetry_instrumentor]
mcp = "amazon.opentelemetry.distro.instrumentation.mcp.instrumentation:McpInstrumentor"

[project.entry-points.opentelemetry_distro]
aws_distro = "amazon.opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
AWS_STEPFUNCTIONS_STATEMACHINE_ARN,
)
from amazon.opentelemetry.distro._aws_resource_attribute_configurator import get_service_attribute
from amazon.opentelemetry.distro.instrumentation.mcp.semconv import MCPSpanAttributes
from amazon.opentelemetry.distro._aws_span_processing_util import (
LOCAL_ROOT,
MAX_KEYWORD_LENGTH,
Expand Down Expand Up @@ -97,6 +98,7 @@
_SERVER_SOCKET_PORT: str = SpanAttributes.SERVER_SOCKET_PORT
_AWS_TABLE_NAMES: str = SpanAttributes.AWS_DYNAMODB_TABLE_NAMES
_AWS_BUCKET_NAME: str = SpanAttributes.AWS_S3_BUCKET
_MCP_METHOD_NAME: str = MCPSpanAttributes.MCP_METHOD_NAME

# Normalized remote service names for supported AWS services
_NORMALIZED_DYNAMO_DB_SERVICE_NAME: str = "AWS::DynamoDB"
Expand Down Expand Up @@ -263,6 +265,9 @@ def _set_remote_service_and_operation(span: ReadableSpan, attributes: BoundedAtt
elif is_key_present(span, _GRAPHQL_OPERATION_TYPE):
remote_service = _GRAPHQL
remote_operation = _get_remote_operation(span, _GRAPHQL_OPERATION_TYPE)
elif is_key_present(span, _MCP_METHOD_NAME) and is_key_present(span, _RPC_SERVICE):
remote_service = _normalize_remote_service_name(span, _get_remote_service(span, _RPC_SERVICE))
remote_operation = _get_remote_operation(span, _MCP_METHOD_NAME)

# Peer service takes priority as RemoteService over everything but AWS Remote.
if is_key_present(span, _PEER_SERVICE) and not is_key_present(span, AWS_REMOTE_SERVICE):
Expand Down
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,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from .version import __version__
from .instrumentation import McpInstrumentor

__all__ = ["McpInstrumentor", "__version__"]
Loading