DevelopmentAugust 14, 2026· via DEV Community

Google GenAI streaming bug miscounts tool calls in Sentry’s JS SDK

Google GenAI streaming bug miscounts tool calls in Sentry’s JS SDK

Image : DEV Community

When a Google GenAI model streams a tool call to control a light or another function, Sentry’s JavaScript SDK was logging that single action twice in its performance traces. One tool call in, two entries out. The issue surfaced in the gen_ai.response.tool_calls attribute, which should list each tool call once. Instead, it repeated the same call—once with parameters under args, once under arguments—leading to duplicated telemetry and potential confusion for developers debugging AI-driven workflows.

The root cause

The bug stems from redundant logic in Sentry’s streaming instrumentation. The handleCandidateContent function in packages/server-utils/src/ai/google-genai/streaming.ts pushed tool calls to the trace from two sources: first, it spread chunk.functionCalls, and later, it iterated over candidate.content.parts to push each functionCall it found. These are not separate data paths. In fact, chunk.functionCalls is a getter that reads the very same candidates[].content.parts array that the second push targets. The first entry keeps the SDK-native shape {id, name, args}, while the second reformats it as {type, id, name, arguments}. The result: two views of the same call, both recorded.

Contrast with non-streaming

The non-streaming instrumentation avoids this duplication entirely. It reads tool calls once from response.functionCalls and emits a single entry per call, maintaining consistency in both count and key naming. Streaming and non-streaming paths thus diverged on the same response, undermining trace reliability for developers relying on consistent AI telemetry.

The fix

The solution is straightforward: treat chunk.functionCalls as the single source of truth. By removing the redundant second push, the SDK ensures one tool call in the model yields one entry in the trace. The fix aligns streaming behavior with non-streaming, restoring predictable telemetry for AI-powered applications monitored by Sentry. A pull request on GitHub implements the change, preventing double-counting without altering the underlying data model.

Why it matters

Miscounted tool calls can distort performance analysis, inflate cost estimates tied to AI function usage, or mislead engineers troubleshooting AI workflows. For teams using Sentry to monitor Google GenAI integrations, this bug introduced noise into traces that could obscure real issues or skew metrics. The fix restores accuracy in telemetry, ensuring developers can trust their data when debugging AI-driven features. It also highlights the importance of consistent instrumentation across streaming and non-streaming paths—a lesson for SDK maintainers building observability tools for generative AI.


Source: DEV Community. AI-assisted editorial synthesis — TechnoExpress.

Read the original source on DEV Community →

← Back to home