Skip to content

bug: FileSpanExporter crashes with circular JSON serialization error #19228

Description

@gsquared94

Bug Description

FileSpanExporter.export() crashes with TypeError: Converting circular structure to JSON when writing OTel spans to a telemetry outfile.

Steps to Reproduce

  1. Enable file-based telemetry:
    { "telemetry": { "enabled": true, "target": "local", "otlpEndpoint": "", "outfile": ".gemini/telemetry.log" } }
  2. 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';
   }
 }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/enterpriseIssues related to Telemetry, Policy, Quota / Licensingstatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions