gemini-cli - ✅(Solved) Fix Bug: Telemetry truncation causes JSON unparseability & couples tracing overhead [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25146Fetched 2026-04-11 06:31:09
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×2added_to_project_v2 ×1cross-referenced ×1parent_issue_added ×1

Fix Action

Fix / Workaround

Furthermore, getTelemetryEnabled() unconditionally activates both lightweight baseline telemetry and detailed tracing overhead (recording massive attributes for tool outputs, file reads, etc.). This violates the principle that baseline telemetry should be cheap and lightweight, inherently forcing users who only want base usage metrics to bear the cost of detailed traces. This issue arose after the OOM memory leaks were patched in PR #23281.

PR fix notes

PR #25136: fix(telemetry): implement bounded structural truncation and decouple traces

Description (problem / solution / changelog)

Summary

This PR implements a bounded structural truncation strategy for telemetry payloads to prevent JSON parsing errors while maintaining OOM safety. It also introduces a new telemetry.traces configuration to explicitly decouple detailed attribute tracing from lightweight baseline telemetry.

Details

  • Structural Truncation: Rewrote truncateForTelemetry to recursively truncate objects by limiting string lengths, array sizes, and traversal depth, instead of applying a hard string slice to stringified JSON. This ensures the resulting output remains perfectly valid JSON.
  • Tracing Decoupling: Introduced a telemetry.traces flag (and GEMINI_TELEMETRY_TRACES_ENABLED env var) defaulting to false. Heavy tracing spans (tool outputs, file reads, model responses) are now strictly opt-in, resolving friction between low-overhead monitoring and deep debugging.
  • Updated all related tests and configuration mocks to support the new getTelemetryTracesEnabled interface.

Related Issues

Resolves the issue where telemetry truncation breaks JSON parseability (context from PR #23281). Fixes #25146

How to Validate

  1. Run the test suite (npm run test) to ensure all trace configurations and truncation unit tests pass.
  2. Enable telemetry (GEMINI_TELEMETRY_ENABLED=true) and ensure basic metrics are logged without trace spans.
  3. Enable traces (GEMINI_TELEMETRY_TRACES_ENABLED=true) and trigger a large tool response to verify the new structural truncation output is valid JSON.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Changed files

  • packages/a2a-server/src/utils/testing_utils.ts (modified, +1/-0)
  • packages/cli/src/config/settingsSchema.ts (modified, +5/-0)
  • packages/cli/src/gemini_cleanup.test.tsx (modified, +2/-0)
  • packages/cli/src/test-utils/mockConfig.ts (modified, +1/-0)
  • packages/cli/src/ui/hooks/useGeminiStream.test.tsx (modified, +2/-0)
  • packages/cli/src/ui/hooks/useGeminiStream.ts (modified, +2/-0)
  • packages/core/src/agents/agent-tool.ts (modified, +1/-0)
  • packages/core/src/config/config.ts (modified, +6/-0)
  • packages/core/src/core/geminiChat.test.ts (modified, +1/-0)
  • packages/core/src/core/geminiChat_network_retry.test.ts (modified, +1/-0)
  • packages/core/src/core/loggingContentGenerator.test.ts (modified, +1/-0)
  • packages/core/src/core/loggingContentGenerator.ts (modified, +3/-0)
  • packages/core/src/scheduler/policy.test.ts (modified, +1/-0)
  • packages/core/src/scheduler/scheduler.test.ts (modified, +2/-0)
  • packages/core/src/scheduler/scheduler.ts (modified, +1/-0)
  • packages/core/src/scheduler/scheduler_hooks.test.ts (modified, +1/-0)
  • packages/core/src/scheduler/scheduler_parallel.test.ts (modified, +1/-0)
  • packages/core/src/scheduler/tool-executor.ts (modified, +1/-0)
  • packages/core/src/telemetry/config.ts (modified, +5/-0)
  • packages/core/src/telemetry/conseca-logger.test.ts (modified, +1/-0)
  • packages/core/src/telemetry/loggers.test.ts (modified, +13/-0)
  • packages/core/src/telemetry/sanitize.test.ts (modified, +1/-0)
  • packages/core/src/telemetry/trace.test.ts (modified, +28/-10)
  • packages/core/src/telemetry/trace.ts (modified, +167/-90)
  • schemas/settings.schema.json (modified, +4/-0)

Code Example

> /about
# paste output here
RAW_BUFFERClick to expand / collapse

What happened?

Currently, the string truncation strategy for telemetry (truncateForTelemetry) breaks JSON parseability. The function relies on safeJsonStringify and cuts the resulting string at 10,000 characters, appending ...[TRUNCATED: original length N]. This results in fundamentally unparseable JSON payloads.

Furthermore, getTelemetryEnabled() unconditionally activates both lightweight baseline telemetry and detailed tracing overhead (recording massive attributes for tool outputs, file reads, etc.). This violates the principle that baseline telemetry should be cheap and lightweight, inherently forcing users who only want base usage metrics to bear the cost of detailed traces. This issue arose after the OOM memory leaks were patched in PR #23281.

What did you expect to happen?

  1. Valid JSON Payloads: Object telemetry payload truncation should rely on bounded structural constraints (limiting max depth, string lengths, and array sizes within the object traversal) so that the final exported output remains perfectly valid and parseable JSON.

  2. Decoupled Tracing Overhead: Heavy trace spans should be completely bypassed unless explicitly opted-into via a new telemetry.traces configuration (backed by GEMINI_TELEMETRY_TRACES_ENABLED), allowing telemetry.enabled to govern lightweight baseline events exclusively.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here
</details>

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

Modify the string truncation strategy for telemetry to ensure JSON parseability by implementing bounded structural constraints, and decouple tracing overhead from baseline telemetry.

Guidance

  • Review the truncateForTelemetry function to limit max depth, string lengths, and array sizes within the object traversal to maintain valid JSON output.
  • Introduce a new configuration option telemetry.traces (backed by GEMINI_TELEMETRY_TRACES_ENABLED) to allow users to opt-in to detailed tracing overhead.
  • Update the getTelemetryEnabled function to only activate lightweight baseline telemetry by default, without enabling detailed tracing overhead.
  • Verify the changes by testing the telemetry output with various input sizes and configurations to ensure parseable JSON payloads.

Example

No explicit code example is provided due to the lack of specific implementation details in the issue.

Notes

The solution may require additional changes to the safeJsonStringify function or other related components to ensure seamless integration with the new truncation strategy and tracing overhead configuration.

Recommendation

Apply a workaround by modifying the truncateForTelemetry function and introducing the new telemetry.traces configuration option to decouple tracing overhead from baseline telemetry, as this approach addresses the root cause of the issue and provides a more flexible and efficient solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - ✅(Solved) Fix Bug: Telemetry truncation causes JSON unparseability & couples tracing overhead [1 pull requests, 1 participants]