Skip to content

Conversation

@RulaKhaled
Copy link
Member

@RulaKhaled RulaKhaled commented Jan 20, 2026

Introduces a new Sentry.setConversationId() API to track multi turn AI conversations across API calls.

We want to leverage each AI frameworks built-in functionalities wherever possible. OpenAIs conversation_id, sessions, etc to create the gen_ai.conversation.id attribute.
However if the framework does not provide such a mechanism (such as Google GenAI or Anthropic) we shall provide a common function: Sentry.setConversationId(...) or sentry_sdk.set_conversation_id(), which adds the conversation ID to the Scope in a similar way as Sentry.setUser() and sentry_sdk.set_user() do. When provided in such a way it will override any automatically detected value.

Why not just add this as an attribute?
it should only appear as a span attribute, not propagate to logs and metrics. This keeps AI conversation context isolated to spans where it's semantically relevant.

@linear
Copy link

linear bot commented Jan 20, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.32 kB +0.46% +115 B 🔺
@sentry/browser - with treeshaking flags 23.83 kB +0.51% +120 B 🔺
@sentry/browser (incl. Tracing) 42.14 kB +0.27% +112 B 🔺
@sentry/browser (incl. Tracing, Profiling) 46.78 kB +0.26% +119 B 🔺
@sentry/browser (incl. Tracing, Replay) 80.75 kB +0.15% +115 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.4 kB +0.15% +101 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 85.47 kB +0.15% +120 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 97.65 kB +0.12% +108 B 🔺
@sentry/browser (incl. Feedback) 42.04 kB +0.28% +117 B 🔺
@sentry/browser (incl. sendFeedback) 30.01 kB +0.41% +120 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.01 kB +0.35% +120 B 🔺
@sentry/browser (incl. Metrics) 26.43 kB +0.47% +122 B 🔺
@sentry/browser (incl. Logs) 26.57 kB +0.41% +108 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.24 kB +0.47% +125 B 🔺
@sentry/react 27.05 kB +0.45% +120 B 🔺
@sentry/react (incl. Tracing) 44.37 kB +0.25% +110 B 🔺
@sentry/vue 29.76 kB +0.41% +119 B 🔺
@sentry/vue (incl. Tracing) 43.93 kB +0.26% +112 B 🔺
@sentry/svelte 25.33 kB +0.45% +113 B 🔺
CDN Bundle 27.89 kB +0.41% +113 B 🔺
CDN Bundle (incl. Tracing) 42.93 kB +0.25% +103 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 43.75 kB +0.25% +105 B 🔺
CDN Bundle (incl. Tracing, Replay) 79.68 kB +0.17% +130 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.11 kB +0.15% +119 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.03 kB +0.15% +121 B 🔺
CDN Bundle - uncompressed 81.6 kB +0.42% +335 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 127.14 kB +0.26% +329 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 129.97 kB +0.26% +329 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.74 kB +0.14% +329 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.54 kB +0.13% +329 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.35 kB +0.13% +329 B 🔺
@sentry/nextjs (client) 46.73 kB +0.23% +107 B 🔺
@sentry/sveltekit (client) 42.51 kB +0.28% +115 B 🔺
@sentry/node-core 52.01 kB +0.21% +108 B 🔺
@sentry/node 165.56 kB +0.06% +87 B 🔺
@sentry/node - without tracing 93.76 kB +0.11% +103 B 🔺
@sentry/aws-serverless 109.28 kB +0.11% +116 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,045 - 9,038 +0%
GET With Sentry 1,687 19% 1,667 +1%
GET With Sentry (error only) 6,033 67% 6,029 +0%
POST Baseline 1,200 - 1,193 +1%
POST With Sentry 588 49% 586 +0%
POST With Sentry (error only) 1,064 89% 1,038 +3%
MYSQL Baseline 3,283 - 3,377 -3%
MYSQL With Sentry 441 13% 497 -11%
MYSQL With Sentry (error only) 2,650 81% 2,733 -3%

View base workflow run

@RulaKhaled RulaKhaled changed the title wip(ai): Support scope-level conversation ID for AI tracing feat(core): Add scope-level conversation ID API to support linking AI conversations Jan 21, 2026
@RulaKhaled RulaKhaled requested a review from Lms24 January 21, 2026 15:18
@RulaKhaled RulaKhaled marked this pull request as ready for review January 22, 2026 13:21
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes! LGTM now!

In the future, we also might want to export conversationIdIntegration from SDKs but as long as there's nothing to configure, I think it's fine to leave it unexported. Happy to leave that up to you :)

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

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.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


if (conversationId) {
span.setAttribute(GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);
}
Copy link

Choose a reason for hiding this comment

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

Integration uses spanStart instead of agreed spanEnd hook

High Severity

The integration uses client.on('spanStart', ...) but the PR discussion explicitly agreed on client.on('spanEnd', ...). With spanStart, the scope's conversation ID is set first, then auto-detected values from OpenAI/LangGraph integrations override it during span execution. The PR description states scope-level values should "override any automatically detected value" which requires spanEnd so the scope value is applied last and takes precedence.

Fix in Cursor Fix in Web

@RulaKhaled RulaKhaled merged commit c5e3249 into develop Jan 23, 2026
212 checks passed
@RulaKhaled RulaKhaled deleted the rolaabuhasna/js-1515-implement-a-new-sentrysetconversationid-api branch January 23, 2026 15:37
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.

3 participants