feat: Implement OpenTelemetry metrics, tracing, and context propagation#68
Open
stenalpjolly wants to merge 8 commits into
Open
feat: Implement OpenTelemetry metrics, tracing, and context propagation#68stenalpjolly wants to merge 8 commits into
stenalpjolly wants to merge 8 commits into
Conversation
09d850b to
23e4011
Compare
…TP transport layers
d23ba63 to
9a07afb
Compare
…t propagation in transport
9a07afb to
e7253d4
Compare
e7253d4 to
e2824f7
Compare
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.
Summary
Integrates OpenTelemetry observability into the Java SDK to provide comprehensive tracing, metrics, and distributed context propagation. All telemetry instrumentation has been implemented at the HTTP transport layer to preserve clean client decoupling.
Expectation & Implementation
HttpMcpTransport.javato keepMcpToolboxClientImpl.javaprotocol-agnostic.initialize,tools/list, andtools/call <tool_name>operations with semantic attributes.traceparent,tracestate) is injected into the_metafield of JSON-RPC request payloads.McpToolboxClientnow extendsAutoCloseableto cleanly track and record total session duration on client termination.Acceptance strategy
Functional Intent & Requirements
initializespan. On success, the negotiated protocol version must be recorded.tools/listandtools/callspans, respectively, recording attributes such asgen_ai.tool.nameandgen_ai.operation.name._metaparameter for all outbound requests.Automated Testing & Verification
OpenTelemetryExtensionto assert that all spans are correctly created, semantic attributes are set, and W3C trace IDs are propagated in outgoing requests.TelemetryHelper,McpToolboxClientImpl,HttpMcpTransport, and all associated classes.Test cases
TelemetryTest.java:testTelemetrySpansAndContextPropagation: Verifies connection, listing, and invocation tracing.testTelemetryAndClientJsonRpcErrors: Verifies JSON-RPC error mapping, fallback code/message parsing, and error recording on active spans.McpToolboxClientImplTest.java: AddedtestGetMergedMetadata_WithMockGenericTransport_NullProviderEmptyHeadersAndNullExtraMetadatato verify metadata resolution defaults.Breaking changes
None. Making
McpToolboxClientextendAutoCloseableis fully backward-compatible.