Skip to content

fix(server-utils): Propagate chats.create() config to google-genai message spans - #23316

Open
zkasuran wants to merge 1 commit into
getsentry:developfrom
zkasuran:fix/google-genai-chat-config-attrs
Open

fix(server-utils): Propagate chats.create() config to google-genai message spans#23316
zkasuran wants to merge 1 commit into
getsentry:developfrom
zkasuran:fix/google-genai-chat-config-attrs

Conversation

@zkasuran

@zkasuran zkasuran commented Aug 12, 2026

Copy link
Copy Markdown

Removing the chats.create() span in #19990 also dropped the config it captured. That config (temperature, top_p, top_k, max_tokens, frequency_penalty, presence_penalty, available_tools, system_instructions) is defined once on the chat and reused for every chat.sendMessage() / chat.sendMessageStream() call, so those spans silently lost it.

This captures the params at chats.create() time and welds model plus config onto each message span, following the approach in the issue. The create-time config is the default and a per-message config overrides it key by key. The create history is intentionally left off the message spans. Non-chat calls (models.generateContent, embeddings) are unaffected because they never receive the chat context.

Root cause: createDeepProxy re-proxied the chat object returned by chats.create() but discarded that call's arguments, so instrumentMethod only ever saw the per-message arguments.

Fixes #20086

AI assistance (Claude, Anthropic) was used in developing this change. The design, review and verification were done by the author. Verified locally: @sentry/server-utils tests (339 passing), the new test failing before and passing after the fix, oxlint --type-aware, oxfmt --check, tsc on the source types, plus a real Gemini run confirming the dropped attributes are restored.

…ssage spans

Removing the chats.create() span dropped the config it captured (temperature,
top_p, top_k, max_tokens, frequency_penalty, presence_penalty, available_tools
and system_instructions). That config is set once on the chat instance and reused
for every chat.sendMessage() and chat.sendMessageStream() call, so those spans
lost it and the trace no longer showed the chat configuration.

Capture the params at chats.create() time and weld model plus config onto each
message span. The create-time config is the default and a per-message config
overrides it key by key. The create history is left off the message spans.

Fixes getsentry#20086
@zkasuran
zkasuran requested a review from a team as a code owner August 12, 2026 06:50
@zkasuran
zkasuran requested review from logaretm and stephanie-anderson and removed request for a team August 12, 2026 06:50

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0f1c434. Configure here.

const callConfig = asConfigObject(callParams?.config);
if (createConfig || callConfig) {
merged.config = { ...createConfig, ...callConfig };
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Config merge mismatches SDK behavior

Medium Severity

mergeChatCreateParams shallow-merges create-time and per-message config, but @google/genai replaces the chat config entirely when sendMessage/sendMessageStream provides one. Spans can then show create-time fields such as systemInstruction, tools, or sampling settings that were not actually sent on that request.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0f1c434. Configure here.

@nicohrubec
nicohrubec requested review from nicohrubec and removed request for stephanie-anderson August 12, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Propagate chat config attributes to chat.sendMessage()/chat.sendMessageStream() spans for Google GenAI

1 participant