fix(telemetry): replace JSON.stringify with safeJsonStringify in file exporters#19244
Conversation
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
… 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
c47a814 to
706ac5e
Compare
There was a problem hiding this comment.
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.
Summary
Fix
FileSpanExporter.export()crash caused byTypeError: Converting circular structure to JSONwhen writing OTel spans to a telemetry outfile.Details
OTel
ReadableSpanobjects contain circular references through their internal span processor chain (BatchSpanProcessor2→BindOnceFuture→_that). TheFileExporter.serialize()method usedJSON.stringify(data, null, 2)which does not handle circular references.Replaced
JSON.stringifywith the existingsafeJsonStringifyutility frompackages/core/src/utils/safeJsonStringify.ts, which uses aWeakSetto detect and replace circular references with[Circular].Also added
GEMINI.mdupdates with a mandatory pre-PR checklist to enforce development workflow compliance.Related Issues
Fixes #19228
How to Validate
npm test -w @google/gemini-cli-core -- src/telemetry/file-exporters.test.ts{ "telemetry": { "enabled": true, "target": "local", "otlpEndpoint": "", "outfile": ".gemini/telemetry.log" } }[Circular]in the output file.Pre-Merge Checklist