Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/src/telemetry/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,21 @@ export function runAsyncGeneratorWithOtelContext<TThis, T>(
/**
* Determines whether to add request/response content to spans.
*
* Matches adk-python, which normalizes the same variable with `.strip().lower()`
* and tests it against a falsy set of `{'0', 'false'}` rather than against an
* affirmative allow-list (see `src/google/adk/telemetry/context.py`).
*
* Defaults to true for now to preserve backward compatibility.
* Once prompt and response logging is well established in ADK, we might start
* a deprecation of request/response content in spans by switching the default
* to false.
*
* @returns false only when ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS is explicitly set to 'false' or '0'
* @returns false only when ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS is set to
* 'false' or '0' (case-insensitive, surrounding whitespace ignored).
*/
function shouldAddRequestResponseToSpans(): boolean {
const envValue = process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS || 'true';
return envValue === 'true' || envValue === '1';
const envValue = (process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS ?? 'true')
.trim()
.toLowerCase();
return envValue !== 'false' && envValue !== '0';
}
64 changes: 58 additions & 6 deletions core/test/telemetry/tracing_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ interface CaptureEnvCase {
* Every value of ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS that the current
* implementation distinguishes, and the payload capture it selects.
*
* `''` and `'TRUE'` are the non-obvious rows: the empty string is falsy so it
* takes the `|| 'true'` default, while `'TRUE'` fails the case-sensitive
* comparison and therefore disables capture.
* The gate is an opt-out: capture stays on unless the value is `'false'` or
* `'0'` after trimming and lowercasing. An unrecognized value is therefore not
* an error condition, it resolves to the default.
*/
const CAPTURE_ENV_CASES: CaptureEnvCase[] = [
{
Expand Down Expand Up @@ -105,13 +105,65 @@ const CAPTURE_ENV_CASES: CaptureEnvCase[] = [
},
{
envValue: 'TRUE',
captureEnabled: true,
description: "captures payloads when the variable is 'TRUE'",
},
{
envValue: 'True',
captureEnabled: true,
description: "captures payloads when the variable is 'True'",
},
{
envValue: 'FALSE',
captureEnabled: false,
description: "redacts payloads when the variable is 'TRUE' (case matters)",
description: "redacts payloads when the variable is 'FALSE'",
},
{
envValue: 'not-a-boolean',
envValue: ' true',
captureEnabled: true,
description: 'captures payloads when the variable is padded with a space',
},
{
envValue: 'true\n',
captureEnabled: true,
description: 'captures payloads when the variable has a trailing newline',
},
{
envValue: ' false ',
captureEnabled: false,
description: 'redacts payloads when the disabling value is padded',
},
{
envValue: '0\n',
captureEnabled: false,
description: 'redacts payloads when the variable is unrecognized',
description: 'redacts payloads when the disabling value has a newline',
},
{
envValue: ' ',
captureEnabled: true,
description: 'captures payloads when the variable is whitespace only',
},
{
envValue: 'yes',
captureEnabled: true,
description: "captures payloads when the variable is 'yes'",
},
{
// 'no' is not a supported disabling value in either SDK, so it resolves to
// the default. Operators relying on it must switch to 'false'.
envValue: 'no',
captureEnabled: true,
description: "captures payloads when the variable is 'no'",
},
{
envValue: 'treu',
captureEnabled: true,
description: "captures payloads when the variable misspells 'true'",
},
{
envValue: 'not-a-boolean',
captureEnabled: true,
description: 'captures payloads when the variable is unrecognized',
},
];

Expand Down
Loading