Skip to content

feat(replays): Record segment names that occur during replay#21851

Open
mjq wants to merge 2 commits into
developfrom
mjq/record-segment-names-in-replay
Open

feat(replays): Record segment names that occur during replay#21851
mjq wants to merge 2 commits into
developfrom
mjq/record-segment-names-in-replay

Conversation

@mjq

@mjq mjq commented Jun 29, 2026

Copy link
Copy Markdown
Member

Record a new segment_names field on replay events.

This will be used in the product on the Transaction Summary page to fetch replays related to a particular named transaction.

This sidesteps our current issue under span streaming where Replay's buffer mode leads to sentry.replay.id attributes often pointing to missing Replays, which broke the assumption that a "query spans by segment name to get replay IDs, then query replays with those IDs" query flow will return a usable number of results.

Closes REPLAY-937.

@linear-code

linear-code Bot commented Jun 29, 2026

Copy link
Copy Markdown

REPLAY-937

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 46.01 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.76 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.8 kB - -
@sentry/browser (incl. Tracing, Replay) 85.31 kB +0.06% +49 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.91 kB +0.09% +61 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 90.01 kB +0.06% +53 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 102.67 kB +0.06% +52 B 🔺
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.32 kB - -
@sentry/vue 32.66 kB - -
@sentry/vue (incl. Tracing) 47.87 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB - -
CDN Bundle (incl. Tracing) 47.95 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.3 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.82 kB +0.07% +49 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.5 kB +0.06% +46 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB +0.06% +45 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.29 kB +0.05% +43 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.55 kB +0.06% +50 B 🔺
CDN Bundle - uncompressed 88.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.18 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.15 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.82 kB +0.1% +197 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.39 kB +0.08% +197 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.35 kB +0.08% +197 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.09 kB +0.08% +197 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.04 kB +0.07% +197 B 🔺
@sentry/nextjs (client) 50.71 kB - -
@sentry/sveltekit (client) 46.41 kB - -
@sentry/core/server 77.67 kB - -
@sentry/core/browser 63.97 kB - -
@sentry/node-core 61.42 kB - -
@sentry/node 122.76 kB +0.01% +1 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.39 kB +0.01% +2 B 🔺
@sentry/node - without tracing 73.14 kB - -
@sentry/aws-serverless 84.02 kB - -
@sentry/cloudflare (withSentry) - minified 180.46 kB - -
@sentry/cloudflare (withSentry) 446.48 kB - -

View base workflow run

@mjq mjq marked this pull request as ready for review July 2, 2026 16:12
@mjq mjq requested a review from a team as a code owner July 2, 2026 16:12
@mjq mjq requested review from Lms24, logaretm and mydea and removed request for a team July 2, 2026 16:12

@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.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8f45b63. Configure here.

const segmentName = spanJSON.name;
if (traceId && segmentName) {
addSegmentDetailsToContext(replay, traceId, segmentName);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty segment name drops trace

Medium Severity

Under span streaming, replay no longer records a trace_id when the segment span’s streamed name is empty. The previous afterSegmentSpanEnd handler still added trace IDs for sampled segment spans regardless of name, so unnamed segments can lose trace_ids on replay events while other linked data still expects them.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 8f45b63. Configure here.

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Got some m/q comments in there. Also would be great to lock down the static spans (non-streaming) by asserting segmentNames in handleAfterSendEvent.test.ts. The afterSendEvent transaction path is writing names untested as far as I can tell.


const traceId = spanJSON.trace_id;
const segmentName = spanJSON.name;
if (traceId && segmentName) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m/q: This couples the trace_id to the segment name: if a sampled segment span has a valid trace_id but an empty name, we now record neither. I think bugbot flagged this, is this intended?

AFAIK, Since traceIds and segmentNames are independent sets with independent caps and dedup, there's no benefit to gating them together, it just drops trace_ids for nameless segments.

Suggest recording the trace_id whenever present and moving the empty-name guard into addSegmentDetailsToContext.

If the coupling is intentional, a comment explaining why would help.

const traceId = event.contexts?.trace?.trace_id;
if (traceId) {
addTraceIdToContext(replay, traceId);
if (traceId && event.transaction) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

m/q: This was if (traceId) before, so a transaction event with a trace_id but no transaction name will no longer record its trace_id.

event.transaction is optional, so this is a behavioral change for nameless transactions. I think we can decouple setting a traceId from setting a segmentNames so that both enrich the replay independently where possible.

What do you think?

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.

2 participants