Practical technical guides / Recent development: ADK Python telemetry credential masking (13 November 2026)

repr Hid the Token but the Trace Did Not: ADK Python Spans Exported OAuth Secrets Until the 13 November Fix

ADK Python issue 7311: spans exported OAuth secrets that repr hid. On 2.14.1 the legacy schema or span content capture still exported them before the 13 November fix.

By Sandeep Belgavi · Published 2026-11-14

ADK Python issue 7311: spans exported OAuth secrets that repr hid. On 2.14.1 the legacy schema or span content capture still exported them before the 13 November fix.

A token hidden from repr and printed in a trace

On 27 September 2026 a user filed google/adk-python issue 7311. ADK's credential models, AuthCredential, OAuth2Auth and their relatives, declare their secret fields with Field(repr=False), so printing a credential shows no token. But the telemetry helper safe_json_serialize turned pydantic models into JSON with model_dump(mode="json"), which renders every field regardless of repr. In the OAuth flow, the arguments of adk_request_credential carry an AuthConfig with the exchanged credential, so the tool-call span exported the OAuth access_token, refresh_token and client_secret in the clear. The report was careful about what it did not claim: rendering repr=False fields in model_dump() is documented pydantic behaviour, not a pydantic bug. The point was that ADK already marked these fields as not for display and already kept a list of credential types for redaction elsewhere, and this serializer consulted neither.

The fix, "mask credential material in the telemetry serializer" (commit b6952874, pull request 7312), was merged on 13 November 2026 with about 490 lines of tests. On 14 November it was not in a release; the latest release was 2.14.1, published on 12 November.

What 2.14.1 actually exports

The issue reproduced the leak on ADK 2.10.0 with no environment variables set. Between 2.10 and 2.14.1 something else changed: release 2.13.0 (23 October) made OpenTelemetry GenAI semantic conventions v2 the default telemetry schema. I ran the issue's own reproduction script against google-adk 2.14.1 in a virtual environment resolved with uv's --exclude-newer 2026-11-14T23:59:59Z, so every dependency was one available on 14 November (pydantic 2.14.3, opentelemetry-sdk 1.45.2, google-genai 2.34.0, fastapi 0.163.0), on Windows 11 with CPython 3.13.5. The script records spans with an in-memory exporter and reports any canary secret found in a span attribute.

EnvironmentSecrets in span attributes
No variables set (schema v2 default)none
ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=1 (legacy schema)all three, in gcp.vertex.agent.tool_call_args
Legacy schema and ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS=falsenone
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLYall three, in gen_ai.tool.call.arguments
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENTall three, in gen_ai.tool.call.arguments
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=EVENT_ONLY or truenone in span attributes

So on 2.14.1 the default no longer puts tool arguments into span attributes, but the two common ways of asking for content in spans, pinning the legacy schema that earlier releases used by default or opting in to span content capture, still export the secrets. In these runs the tool response did not carry the secrets on 2.14.1, unlike the issue's 2.10.0 output. The script checks span attributes only; I did not inspect log events, so EVENT_ONLY and true are "not in span attributes", not "safe".

I then installed ADK from the fix commit b6952874 itself, in a second environment resolved the same way, and ran the same seven configurations: no secret reached a span attribute in any of them, including the legacy schema and both span capture modes.

If you ran an ADK Python release before 2.13.0 with default tracing and the OAuth credential flow, the issue's reproduction says your exported spans contained these values. If you run 2.13 or later with span content capture or the legacy schema, my runs say they still did on 2.14.1, and stopped at the fix commit.

The general bug: hiding is not masking

The same gap exists outside ADK and outside pydantic. In standard Python, dataclasses.field(repr=False) hides a value from repr(), and dataclasses.asdict() returns it. Any "turn the object into a dict, then JSON" helper inherits that. The companion example builds a tool-call object with an OAuth credential whose secrets are runtime-generated canary strings, exports it through a naive serializer and through a masking one into an in-memory exporter, and reports what reached the attributes:

  • repr() shows none of the canaries;
  • the naive serializer exports all three from the credential, plus an access token that arrived as a plain dictionary in a tool response;
  • the masking serializer exports none, and still keeps an ordinary key such as token_count.

The masking serializer does what the ADK fix does, in miniature. It masks by type while it can still see the live objects, before dumping flattens them into dictionaries, and it masks by shape for credential payloads that arrive as plain dictionaries:

CREDENTIAL_TYPES = (OAuthCredential,)
SECRET_KEYS = {'access_token', 'refresh_token', 'client_secret', 'id_token', 'password', 'api_key'}

def _mask(value):
    if isinstance(value, CREDENTIAL_TYPES):
        return '<redacted>'                                       # by declared type
    if dataclasses.is_dataclass(value) and not isinstance(value, type):
        return {f.name: _mask(getattr(value, f.name)) for f in dataclasses.fields(value)}
    if isinstance(value, dict):
        return {k: ('<redacted>' if k in SECRET_KEYS else _mask(v)) for k, v in value.items()}
    if isinstance(value, (list, tuple)):
        return [_mask(v) for v in value]
    return value

The ADK change walks the live value alongside its dump for the same reason: once a model is dumped to a dict, its type is gone and only key names remain. Its tests also cover aliases, root models, computed fields and reference cycles, which is where a short version like this one would leak.

Why repr=False was never a control

repr=False answers a display question: what appears when an object is printed in a log line or a debugger. It does not change what the object holds or what any serializer emits. Pydantic has a type for the other question: a field declared as SecretStr prints as SecretStr('********'), and model_dump(mode="json") and model_dump_json() both emit '********'; only an explicit get_secret_value() returns the value. Checked locally with pydantic 2.13.3, a model with one SecretStr field and one Field(repr=False) string dumps the first as asterisks and the second in the clear. Typing secrets as secret types moves masking into the model instead of every serializer. It does not remove the need for the serializer fix, because credentials also arrive as plain dictionaries, which have no type to consult.

What to do if you run ADK Python agents with OAuth tools

  1. Find out what your spans contain. Check whether you pin ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=1 or set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to a span mode, and which ADK version you ran when.
  2. Search stored traces. Query your tracing backend for the attributes gcp.vertex.agent.tool_call_args, gcp.vertex.agent.tool_response and gen_ai.tool.call.arguments containing access_token, refresh_token or client_secret. The companion includes a small scanner for exported span JSON that walks nested JSON strings and reports secret-named keys holding values.
  3. Revoke and reissue anything found. Refresh tokens and client secrets are long-lived; deleting the spans does not undo a copy already in a backend, an export or a support case.
  4. Turn off content in spans until you upgrade. Set ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS=false if you use the legacy schema, and do not use a span mode of the OTel capture variable. In my runs that removed the secrets from span attributes on 2.14.1.
  5. Upgrade to a release that contains b6952874, and keep a canary test in CI: run one tool call with a fake credential through your real exporter configuration and fail if the canary appears in any attribute.

Treat traces as a data store

Traces are often configured by platform teams for latency and errors and then quietly start carrying content when someone turns on capture for debugging. A trace backend then becomes a store of tool arguments and responses with broad read access and long retention. Give it the controls you give any store of customer data: an explicit decision about which content is captured, masking at the source, not in the backend, retention limits, and access reviews. Masking in the backend is too late; the secret has already left the process.

Failure modes

  • A second serializer path. The fix notes that masking applies only to values passed through safe_json_serialize; the experimental semantic-convention code uses its own serializer. Test the exporter configuration you run, not a function.
  • Secrets under unexpected names, such as a vendor's x-api-key header inside a tool argument. Extend the shape list from your own tools.
  • Masking that also removes keys you need, such as token_count. Match whole key names, and test that ordinary fields survive.
  • Canary tests that use realistic-looking secrets and trip a secret scanner in CI. Build canaries at run time from an obviously fake prefix.

Limits

I ran the issue's script on 2.14.1 and on the fix commit, each with a dependency set dated 14 November; I did not run ADK 2.10.0, and I did not inspect log events or the experimental serializer separately. The companion uses dataclasses to show the mechanism, not ADK.

Primary references and authorship

Sources dated on or before 14 November 2026. Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/span_credential_masking. Views are my own and do not represent any employer, past or present.