Skip to content

fix(telemetry): replace JSON.stringify with safeJsonStringify in file exporters#19244

Merged
jerop merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/file-exporter-circular-json
Feb 17, 2026
Merged

fix(telemetry): replace JSON.stringify with safeJsonStringify in file exporters#19244
jerop merged 1 commit intogoogle-gemini:mainfrom
gsquared94:fix/file-exporter-circular-json

Conversation

@gsquared94
Copy link
Contributor

Summary

Fix FileSpanExporter.export() crash caused by TypeError: Converting circular structure to JSON when writing OTel spans to a telemetry outfile.

Details

OTel ReadableSpan objects contain circular references through their internal span processor chain (BatchSpanProcessor2BindOnceFuture_that). The FileExporter.serialize() method used JSON.stringify(data, null, 2) which does not handle circular references.

Replaced JSON.stringify with the existing safeJsonStringify utility from packages/core/src/utils/safeJsonStringify.ts, which uses a WeakSet to detect and replace circular references with [Circular].

Also added GEMINI.md updates with a mandatory pre-PR checklist to enforce development workflow compliance.

Related Issues

Fixes #19228

How to Validate

  1. Run the new unit tests:
    npm test -w @google/gemini-cli-core -- src/telemetry/file-exporters.test.ts
  2. Enable file-based telemetry and verify spans are written without crash:
    { "telemetry": { "enabled": true, "target": "local", "otlpEndpoint": "", "outfile": ".gemini/telemetry.log" } }
    GEMINI_DEV_TRACING=true gemini
  3. Verify circular references appear as [Circular] in the output file.

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

@gsquared94 gsquared94 requested review from a team as code owners February 17, 2026 08:28
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gsquared94, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where the telemetry file exporters would crash when attempting to serialize OpenTelemetry objects containing circular references. The solution involves integrating a pre-existing safe JSON stringification utility, which detects and handles these circular structures, thereby preventing application failures. The changes are thoroughly validated with new unit tests, and the project's development guidelines have been updated to include a mandatory pre-PR checklist to improve overall code quality and adherence to best practices.

Highlights

  • Telemetry Crash Fix: Resolved a TypeError: Converting circular structure to JSON crash that occurred when OpenTelemetry spans with circular references were written to a telemetry outfile.
  • Safe JSON Serialization: Replaced JSON.stringify with the existing safeJsonStringify utility in FileExporter.serialize() to gracefully handle circular references by replacing them with [Circular].
  • New Unit Tests: Added comprehensive unit tests for FileSpanExporter, FileLogExporter, and FileMetricExporter to ensure correct serialization, including handling of circular references, and proper error reporting.
  • Development Workflow Enhancement: Introduced a mandatory pre-PR checklist in GEMINI.md to enforce development workflow compliance and ensure consistent quality before pull request creation.
Changelog
  • GEMINI.md
    • Added a new section for mandatory pre-PR checklist under 'Development Conventions'.
  • packages/core/src/telemetry/file-exporters.test.ts
    • Introduced new unit tests for FileSpanExporter, FileLogExporter, and FileMetricExporter.
  • packages/core/src/telemetry/file-exporters.ts
    • Imported safeJsonStringify utility.
    • Replaced JSON.stringify with safeJsonStringify in the serialize method to prevent crashes from circular references.
Activity
  • The author has added new unit tests to cover the changes.
  • The author has validated the fix by enabling file-based telemetry and verifying spans are written without crashing, and that circular references appear as [Circular] in the output.
  • The author has checked off the 'Added/updated tests' item in the pre-merge checklist.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 17, 2026
… exporters

FileExporter.serialize() crashes with TypeError: Converting circular structure
to JSON when writing OTel spans to a telemetry outfile. OTel ReadableSpan
objects contain circular references through their internal span processor chain
(BatchSpanProcessor2 -> BindOnceFuture -> _that).

Replace JSON.stringify with the existing safeJsonStringify utility which handles
circular references by replacing them with [Circular].

Fixes google-gemini#19228
@gsquared94 gsquared94 force-pushed the fix/file-exporter-circular-json branch from c47a814 to 706ac5e Compare February 17, 2026 08:30
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the TypeError: Converting circular structure to JSON by integrating safeJsonStringify into the file exporters. The addition of comprehensive unit tests, including specific cases for circular references, thoroughly validates the fix and ensures the robustness of the telemetry export mechanism. The changes are well-implemented and directly resolve the identified issue.

@gsquared94 gsquared94 requested a review from jerop February 17, 2026 08:31
@jerop jerop added this pull request to the merge queue Feb 17, 2026
Merged via the queue into google-gemini:main with commit bbf6800 Feb 17, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: FileSpanExporter crashes with circular JSON serialization error

2 participants