fix(core): Set conversation_id only on gen_ai spans#20274
fix(core): Set conversation_id only on gen_ai spans#20274nicohrubec merged 4 commits intodevelopfrom
conversation_id only on gen_ai spans#20274Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Cloudflare
Core
Deps
Other
Bug Fixes 🐛Deno
Other
Internal Changes 🔧Ci
Deps
Deps Dev
Other
🤖 This preview updates automatically when you update the PR. |
size-limit report 📦
|
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 81df583. Configure here.
| // Only apply conversation ID to gen_ai spans | ||
| if (!spanToJSON(span).op?.startsWith('gen_ai.')) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Conversation ID skipped for Vercel AI spans due to hook ordering
High Severity
The spanToJSON(span).op check will always fail for Vercel AI spans because the gen_ai.* op is set by the Vercel AI integration's own spanStart handler (onVercelAiSpanStart), which is registered after the conversationIdIntegration handler. Since conversationIdIntegration uses setup() and is a default integration, while Vercel AI registers its handler in afterAllSetup() (Node) or later in setup() order (Cloudflare), the conversation ID handler always runs first — when op is still undefined. This means conversation_id will never be applied to Vercel AI gen_ai spans, which is a regression from the previous behavior.
Reviewed by Cursor Bugbot for commit 81df583. Configure here.
There was a problem hiding this comment.
LGTM for now. To avoid the problem of spanStart order with vercel AI, we could also think about using something like the processSpan hook in the future (this is only scoped to span streaming for now but we could think about alternatives). At this point, the op is already there and we already converted the span to JSON. Meaning, we can avoid the performance overhead of the spanToJSON call. No need to do this right now, just a thought.
(we could also use an event processor and modify the child spans of a transaction but given span streaming, I'd rather avoid this for the moment xD)
|
@Lms24 Good to know thanks! Maybe we can revisit this after we have fully adopted span streaming |


We should only set the
conversation_idforgen_aispans. These are the only spans for which this attribute is relevant and setting it on other spans can lead to unnecessarily slow queries in the product.This works fine for all our AI integrations except Vercel. This is because the Vercel ai integration also registers a
spanStarthook that transforms Vercel spans to sentrygen_aispans. The conversation id integration fires before that happens, so we have to special case the Vercel ai spans here for this to work properly.Closes #20272