feat(observability): add OTEL root and client spans for MCP flows#3872
Open
feat(observability): add OTEL root and client spans for MCP flows#3872
Conversation
e46fcc4 to
fb014ce
Compare
Member
|
Thanks @vishu-bh. Comprehensive OTEL instrumentation across MCP transports — this will be very valuable for production debugging. A few notes:
|
Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
fb014ce to
f7bb46a
Compare
Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issue
Closes #3858
Refs #3736
📝 Summary
This PR builds out the gateway-side OpenTelemetry trace tree for MCP traffic and plugin execution.
Implemented so far:
/rpc,/mcp, server-scoped MCP routes, and internal MCP transport hopstraceparent/tracestateinjectionmcp.client.callmcp.client.initializemcp.client.requestmcp.client.responseplugin.hook.invokefor the hook chainplugin.executefor each plugin executionCurrent gateway-side trace shape for an MCP tool call is now roughly:
POST /rpctool.invokeplugin.hook.invoke/plugin.executefor pre-invoke hooks when configuredmcp.client.callmcp.client.initializemcp.client.requestmcp.client.responseplugin.hook.invoke/plugin.executefor post-invoke hooks when configuredUpstream server spans for non-Python services such as
fast-time-serverare not part of this PR. Those services can join the same trace by extractingtraceparent/tracestateand exporting OTEL spans from their own runtime.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageFocused verification run:
python -m py_compile mcpgateway/observability.py mcpgateway/main.py mcpgateway/plugins/framework/external/mcp/server/runtime.py mcpgateway/services/tool_service.py tests/unit/mcpgateway/test_observability.py tests/unit/mcpgateway/plugins/framework/external/mcp/server/test_runtime_coverage.py tests/unit/mcpgateway/services/test_tool_service.py tests/unit/mcpgateway/plugins/framework/test_observability.pypytest tests/unit/mcpgateway/test_observability.py tests/unit/mcpgateway/plugins/framework/external/mcp/server/test_runtime_coverage.py -qpytest tests/unit/mcpgateway/services/test_tool_service.py -k "streamablehttp_creates_client_lifecycle_spans or invoke_tool_mcp_streamablehttp or prepare_rust_mcp_tool_execution_injects_w3c_trace_context_into_plan_headers" -qpytest tests/unit/mcpgateway/plugins/framework/test_observability.py -q✅ Checklist
make black isort pre-commit)📓 Notes