fix(server-utils): Propagate chats.create() config to google-genai message spans - #23316
Open
zkasuran wants to merge 1 commit into
Open
fix(server-utils): Propagate chats.create() config to google-genai message spans#23316zkasuran wants to merge 1 commit into
zkasuran wants to merge 1 commit into
Conversation
…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
requested review from
logaretm and
stephanie-anderson
and removed request for
a team
August 12, 2026 06:50
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 }; | ||
| } |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 0f1c434. Configure here.
nicohrubec
requested review from
nicohrubec
and removed request for
stephanie-anderson
August 12, 2026 08:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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 everychat.sendMessage()/chat.sendMessageStream()call, so those spans silently lost it.This captures the params at
chats.create()time and weldsmodelplusconfigonto 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 createhistoryis intentionally left off the message spans. Non-chat calls (models.generateContent, embeddings) are unaffected because they never receive the chat context.Root cause:
createDeepProxyre-proxied the chat object returned bychats.create()but discarded that call's arguments, soinstrumentMethodonly 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-utilstests (339 passing), the new test failing before and passing after the fix,oxlint --type-aware,oxfmt --check,tscon the source types, plus a real Gemini run confirming the dropped attributes are restored.