fix(telemetry): suppress high-cardinality httpx spans for MCP calls - #287
Closed
jeanscherf wants to merge 2 commits into
Closed
fix(telemetry): suppress high-cardinality httpx spans for MCP calls#287jeanscherf wants to merge 2 commits into
jeanscherf wants to merge 2 commits into
Conversation
cloud-sdk agents making hundreds of MCP calls (e.g. scoring-agent with 2,159 calls) produced monster traces of 60K+ spans because HTTPXClientInstrumentor creates a child span for every outbound httpx request regardless of cardinality. The span must still be created so that the W3C traceparent header is injected into the outgoing request before the transport runs. Excluded URLs in the upstream instrumentor skip header injection entirely, which breaks distributed trace context propagation downstream. Instead, a request hook marks high-cardinality spans with sap.cloud_sdk.suppress=True (sync and async), and GenAIAttributeTransformer filters them at export time. Traceparent propagates correctly; nothing is sent to the collector for these spans. URL patterns default to /v1/mcp/ and are overridable via SAP_CLOUD_SDK_HIGH_CARDINALITY_URLS (comma-separated substrings).
jeanscherf
marked this pull request as draft
August 26, 2026 14:16
Remove /v1/mcp/ as the default pattern. By default no spans are suppressed so MCP call visibility is preserved for all agents. Deploy SAP_CLOUD_SDK_HIGH_CARDINALITY_URLS=pattern1,pattern2 to opt specific agents or workloads into suppression.
Member
Author
|
Closing: the httpx instrumentation is working correctly. One span per outbound request is standard OTel behavior. Monster traces from high fan-out agents are a signal about agent design, not an instrumentation bug — suppressing those spans in the SDK would hide useful diagnostic information. The a2a-python-sdk EventQueue polling pattern is a separate issue to be addressed upstream. |
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
HTTPXClientInstrumentorcreates a child span for every httpx requestexcluded_urlscannot be used as a fix: it skips both span creation and W3Ctraceparentheader injection, which breaks distributed trace context propagation to downstream servicesrequest_hookmarks spans for URLs matchingSAP_CLOUD_SDK_HIGH_CARDINALITY_URLSwithsap.cloud_sdk.suppress=True, andGenAIAttributeTransformerfilters them at export time — the span is created (so traceparent propagates correctly) but never exported to the collectorBehaviour
Configure via env:
SAP_CLOUD_SDK_HIGH_CARDINALITY_URLS=pattern1,pattern2Test plan
tests/core/unit/telemetry/test_genai_attribute_transformer.py— two new tests: spans markedsap.cloud_sdk.suppress=Trueare filtered; suppressed-only batches pass an empty list to the wrapped exporter