Bug Description
FileSpanExporter.export() crashes with TypeError: Converting circular structure to JSON when writing OTel spans to a telemetry outfile.
Steps to Reproduce
- Enable file-based telemetry:
{ "telemetry": { "enabled": true, "target": "local", "otlpEndpoint": "", "outfile": ".gemini/telemetry.log" } }
- Run
GEMINI_DEV_TRACING=true gemini and send any prompt
Error
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'BatchSpanProcessor2'
| property '_shutdownOnce' -> object with constructor 'BindOnceFuture'
--- property '_that' closes the circle
Root Cause
FileExporter.serialize() in packages/core/src/telemetry/file-exporters.ts uses JSON.stringify(data, null, 2) which does not handle circular references. OTel ReadableSpan objects contain circular references through their internal span processor chain.
Suggested Fix
Replace JSON.stringify with the existing safeJsonStringify utility:
+import { safeJsonStringify } from '../utils/safeJsonStringify.js';
class FileExporter {
protected serialize(data: unknown): string {
- return JSON.stringify(data, null, 2) + '\n';
+ return safeJsonStringify(data, 2) + '\n';
}
}
Bug Description
FileSpanExporter.export()crashes withTypeError: Converting circular structure to JSONwhen writing OTel spans to a telemetry outfile.Steps to Reproduce
{ "telemetry": { "enabled": true, "target": "local", "otlpEndpoint": "", "outfile": ".gemini/telemetry.log" } }GEMINI_DEV_TRACING=true geminiand send any promptError
Root Cause
FileExporter.serialize()inpackages/core/src/telemetry/file-exporters.tsusesJSON.stringify(data, null, 2)which does not handle circular references. OTelReadableSpanobjects contain circular references through their internal span processor chain.Suggested Fix
Replace
JSON.stringifywith the existingsafeJsonStringifyutility: