fix(telemetry): attribute internal SDK calls to their caller module#200
Merged
Conversation
f893daa to
aacbd09
Compare
LucasAlvesSoares
previously approved these changes
Jul 9, 2026
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.

Description
When one SDK module calls another under the hood, the resulting OpenTelemetry metric was emitted with
sap.cloud_sdk.source="user-facing"— indistinguishable from a real customer call. This double-counted customer activity in usage dashboards.Canonical example:
AgentGatewayClient.list_mcp_tools()internally callsdestination.get_destination(...)to resolve auth tokens for MCP servers. Before this PR, that internal call was billed as if a customer had directly calledget_destinationthemselves.This PR fixes that by:
Callee-side — adds
_telemetry_sourcesupport to the two factories that get called internally today:destination(all three factories:create_client,create_fragment_client,create_certificate_client) andagentgateway.create_client. Each factory forwards it to the client constructor, which stores it asself._telemetry_source.Caller-side — passes
_telemetry_source=Module.<caller>at every internal cross-module call site:agentgateway/_lob.py:91→Module.AGENTGATEWAYagentgateway/_fragments.py:38→Module.AGENTGATEWAYextensibility/client.py:615→Module.EXTENSIBILITYextensibility/_ums_transport.py:452→Module.EXTENSIBILITYcore/data_anonymization/_http_transport.py:366and:379→Module.DATA_ANONYMIZATIONcore/auditlog_ng/__init__.py:119→Module.AUDITLOG_NGRelated Issue
N/A
Type of Change
How to Test
Unit tests
uv run pytest tests/destination/unit/test_init.py -v -k "TelemetrySource"— 6 tests covering the three destination factories.uv run pytest tests/agentgateway/unit/test_agw_client.py -v -k "TelemetrySource"— 2 tests for the agentgateway factory.uv run pytest tests/ -m "not integration"— full unit-test suite. Expected: all tests pass.End-to-end verification via local OpenTelemetry:
destination(e.g.AgentGatewayClient.list_mcp_tools).sap.cloud_sdk.sourcefilter shows two values —user-facing(direct customer calls) andagentgateway(internal calls). Before the fix, onlyuser-facingappeared.Checklist
Breaking Changes
None.
_telemetry_sourceis a keyword-only argument with a default ofNone, so all existing callers ofcreate_client()continue to work unchanged.Additional Notes
Adding the kwarg to production call sites broke a few pre-existing strict-signature checks. Fixed by loosening them to check only what each test cares about:
assert_called_once_with(instance=...)→assert_called_once() + call_args.kwargs["instance"] == ...lambda: fake_client→lambda **_: fake_clientBoth changes decouple the tests from unrelated production kwargs.