-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(replay): Linked errors not resetting session id #17854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
billyvg
merged 17 commits into
develop
from
billy/replay-575-replay-w-linked-errors-from-prior-week
Oct 28, 2025
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b51a7a9
fix(replay): Linked errors not resetting session id
billyvg 0d03553
add a new "dirty" flag to session
billyvg 60e298a
add dirty flag to session
billyvg d9f8022
update tests
billyvg 2ab84b6
fix tests
billyvg 46cbaf2
fix tests
billyvg 2499b42
Merge branch 'develop' into billy/replay-575-replay-w-linked-errors-f…
billyvg e80eb02
Merge branch 'develop' into billy/replay-575-replay-w-linked-errors-f…
billyvg 7630edd
Apply suggestion from @billyvg
billyvg d464260
formatting
billyvg f4f016f
fix flake
billyvg a47855b
wait for 2nd replay segment
billyvg 2bed2d3
formatting
billyvg 682005d
fix timing issues
billyvg 852d464
remove flakey browser test and move test to integration test
billyvg 1a0bc8a
remove unused
billyvg 6377220
Merge branch 'develop' into billy/replay-575-replay-w-linked-errors-f…
billyvg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
dev-packages/browser-integration-tests/suites/replay/bufferStalledRequests/init.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
| window.Replay = Sentry.replayIntegration({ | ||
| flushMinDelay: 200, | ||
| flushMaxDelay: 200, | ||
| minReplayDuration: 0, | ||
| stickySession: true, | ||
| }); | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| sampleRate: 1, | ||
| replaysSessionSampleRate: 0.0, | ||
| replaysOnErrorSampleRate: 1.0, | ||
|
|
||
| integrations: [window.Replay], | ||
| }); |
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/replay/bufferStalledRequests/subject.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| document.getElementById('error1').addEventListener('click', () => { | ||
| throw new Error('First Error'); | ||
| }); | ||
|
|
||
| document.getElementById('error2').addEventListener('click', () => { | ||
| throw new Error('Second Error'); | ||
| }); | ||
|
|
||
| document.getElementById('click').addEventListener('click', () => { | ||
| // Just a click for interaction | ||
| }); |
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/replay/bufferStalledRequests/template.html
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button id="error1">Throw First Error</button> | ||
| <button id="error2">Throw Second Error</button> | ||
| <button id="click">Click me</button> | ||
| </body> | ||
| </html> |
330 changes: 330 additions & 0 deletions
330
dev-packages/browser-integration-tests/suites/replay/bufferStalledRequests/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,330 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { envelopeRequestParser, waitForErrorRequest } from '../../../utils/helpers'; | ||
| import { | ||
| getReplaySnapshot, | ||
| isReplayEvent, | ||
| shouldSkipReplayTest, | ||
| waitForReplayRunning, | ||
| } from '../../../utils/replayHelpers'; | ||
|
|
||
| sentryTest( | ||
| 'buffer mode remains after interrupting error event ingest', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipReplayTest() || browserName === 'webkit') { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| let errorCount = 0; | ||
| let replayCount = 0; | ||
| const errorEventIds: string[] = []; | ||
| const replayIds: string[] = []; | ||
| let firstReplayEventResolved: (value?: unknown) => void = () => {}; | ||
| // Need TS 5.7 for withResolvers | ||
| const firstReplayEventPromise = new Promise(resolve => { | ||
| firstReplayEventResolved = resolve; | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
|
|
||
| await page.route('https://dsn.ingest.sentry.io/**/*', async route => { | ||
| const event = envelopeRequestParser(route.request()); | ||
|
|
||
| // Track error events | ||
| if (event && !event.type && event.event_id) { | ||
| errorCount++; | ||
| errorEventIds.push(event.event_id); | ||
| if (event.tags?.replayId) { | ||
| replayIds.push(event.tags.replayId as string); | ||
|
|
||
| if (errorCount === 1) { | ||
| firstReplayEventResolved(); | ||
| // intentional so that it never resolves, we'll force a reload instead to interrupt the normal flow | ||
| await new Promise(resolve => setTimeout(resolve, 100000)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Track replay events and simulate failure for the first replay | ||
| if (event && isReplayEvent(event)) { | ||
| replayCount++; | ||
| } | ||
|
|
||
| // Success for other requests | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| // Wait for replay to initialize | ||
| await waitForReplayRunning(page); | ||
|
|
||
| waitForErrorRequest(page); | ||
| await page.locator('#error1').click(); | ||
|
|
||
| // This resolves, but the route doesn't get fulfilled as we want the reload to "interrupt" this flow | ||
| await firstReplayEventPromise; | ||
| expect(errorCount).toBe(1); | ||
| expect(replayCount).toBe(0); | ||
| expect(replayIds).toHaveLength(1); | ||
|
|
||
| const firstSession = await getReplaySnapshot(page); | ||
| const firstSessionId = firstSession.session?.id; | ||
| expect(firstSessionId).toBeDefined(); | ||
| expect(firstSession.session?.sampled).toBe('buffer'); | ||
| expect(firstSession.session?.dirty).toBe(true); | ||
| expect(firstSession.recordingMode).toBe('buffer'); | ||
|
|
||
| await page.reload(); | ||
| const secondSession = await getReplaySnapshot(page); | ||
| expect(secondSession.session?.sampled).toBe('buffer'); | ||
| expect(secondSession.session?.dirty).toBe(true); | ||
| expect(secondSession.recordingMode).toBe('buffer'); | ||
| expect(secondSession.session?.id).toBe(firstSessionId); | ||
| expect(secondSession.session?.segmentId).toBe(0); | ||
| }, | ||
| ); | ||
|
|
||
| sentryTest.only( | ||
| 'buffer mode remains after interrupting replay flush', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipReplayTest() || browserName === 'webkit') { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| let errorCount = 0; | ||
| let replayCount = 0; | ||
| const errorEventIds: string[] = []; | ||
| const replayIds: string[] = []; | ||
| let firstReplayEventResolved: (value?: unknown) => void = () => {}; | ||
| // Need TS 5.7 for withResolvers | ||
| const firstReplayEventPromise = new Promise(resolve => { | ||
| firstReplayEventResolved = resolve; | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
|
|
||
| await page.route('https://dsn.ingest.sentry.io/**/*', async route => { | ||
| const event = envelopeRequestParser(route.request()); | ||
|
|
||
| // Track error events | ||
| if (event && !event.type && event.event_id) { | ||
| errorCount++; | ||
| errorEventIds.push(event.event_id); | ||
| if (event.tags?.replayId) { | ||
| replayIds.push(event.tags.replayId as string); | ||
| } | ||
| } | ||
|
|
||
| // Track replay events and simulate failure for the first replay | ||
| if (event && isReplayEvent(event)) { | ||
| replayCount++; | ||
| if (replayCount === 1) { | ||
| firstReplayEventResolved(); | ||
| // intentional so that it never resolves, we'll force a reload instead to interrupt the normal flow | ||
| await new Promise(resolve => setTimeout(resolve, 100000)); | ||
| } | ||
| } | ||
|
|
||
| // Success for other requests | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| // Wait for replay to initialize | ||
| await waitForReplayRunning(page); | ||
|
|
||
| await page.locator('#error1').click(); | ||
| await firstReplayEventPromise; | ||
| expect(errorCount).toBe(1); | ||
| expect(replayCount).toBe(1); | ||
| expect(replayIds).toHaveLength(1); | ||
|
|
||
| // Get the first session info | ||
| const firstSession = await getReplaySnapshot(page); | ||
| const firstSessionId = firstSession.session?.id; | ||
| expect(firstSessionId).toBeDefined(); | ||
| expect(firstSession.session?.sampled).toBe('buffer'); | ||
| expect(firstSession.session?.dirty).toBe(true); | ||
| expect(firstSession.recordingMode).toBe('buffer'); // But still in buffer mode | ||
|
|
||
| await page.reload(); | ||
| await waitForReplayRunning(page); | ||
| const secondSession = await getReplaySnapshot(page); | ||
| expect(secondSession.session?.sampled).toBe('buffer'); | ||
| expect(secondSession.session?.dirty).toBe(true); | ||
| expect(secondSession.session?.id).toBe(firstSessionId); | ||
| expect(secondSession.session?.segmentId).toBe(1); | ||
| // Because a flush attempt was made and not allowed to complete, segmentId increased from 0, | ||
| // so we resume in session mode | ||
| expect(secondSession.recordingMode).toBe('session'); | ||
| }, | ||
| ); | ||
|
|
||
| sentryTest( | ||
| 'starts a new session after interrupting replay flush and session "expires"', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipReplayTest() || browserName === 'webkit') { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| let errorCount = 0; | ||
| let replayCount = 0; | ||
| const errorEventIds: string[] = []; | ||
| const replayIds: string[] = []; | ||
| let firstReplayEventResolved: (value?: unknown) => void = () => {}; | ||
| // Need TS 5.7 for withResolvers | ||
| const firstReplayEventPromise = new Promise(resolve => { | ||
| firstReplayEventResolved = resolve; | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
|
|
||
| await page.route('https://dsn.ingest.sentry.io/**/*', async route => { | ||
| const event = envelopeRequestParser(route.request()); | ||
|
|
||
| // Track error events | ||
| if (event && !event.type && event.event_id) { | ||
| errorCount++; | ||
| errorEventIds.push(event.event_id); | ||
| if (event.tags?.replayId) { | ||
| replayIds.push(event.tags.replayId as string); | ||
| } | ||
| } | ||
|
|
||
| // Track replay events and simulate failure for the first replay | ||
| if (event && isReplayEvent(event)) { | ||
| replayCount++; | ||
| if (replayCount === 1) { | ||
| firstReplayEventResolved(); | ||
| // intentional so that it never resolves, we'll force a reload instead to interrupt the normal flow | ||
| await new Promise(resolve => setTimeout(resolve, 100000)); | ||
| } | ||
| } | ||
|
|
||
| // Success for other requests | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| // Wait for replay to initialize | ||
| await waitForReplayRunning(page); | ||
|
|
||
| // Trigger first error - this should change session sampled to "session" | ||
| await page.locator('#error1').click(); | ||
| await firstReplayEventPromise; | ||
| expect(errorCount).toBe(1); | ||
| expect(replayCount).toBe(1); | ||
| expect(replayIds).toHaveLength(1); | ||
|
|
||
| // Get the first session info | ||
| const firstSession = await getReplaySnapshot(page); | ||
| const firstSessionId = firstSession.session?.id; | ||
| expect(firstSessionId).toBeDefined(); | ||
| expect(firstSession.session?.sampled).toBe('buffer'); | ||
| expect(firstSession.session?.dirty).toBe(true); | ||
| expect(firstSession.recordingMode).toBe('buffer'); // But still in buffer mode | ||
|
|
||
| // Now expire the session by manipulating session storage | ||
| // Simulate session expiry by setting lastActivity to a time in the past | ||
| await page.evaluate(() => { | ||
| const replayIntegration = (window as any).Replay; | ||
| const replay = replayIntegration['_replay']; | ||
|
|
||
| // Set session as expired (15 minutes ago) | ||
| if (replay.session) { | ||
| const fifteenMinutesAgo = Date.now() - 15 * 60 * 1000; | ||
| replay.session.lastActivity = fifteenMinutesAgo; | ||
| replay.session.started = fifteenMinutesAgo; | ||
|
|
||
| // Also update session storage if sticky sessions are enabled | ||
| const sessionKey = 'sentryReplaySession'; | ||
| const sessionData = sessionStorage.getItem(sessionKey); | ||
| if (sessionData) { | ||
| const session = JSON.parse(sessionData); | ||
| session.lastActivity = fifteenMinutesAgo; | ||
| session.started = fifteenMinutesAgo; | ||
| sessionStorage.setItem(sessionKey, JSON.stringify(session)); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| await page.reload(); | ||
| const secondSession = await getReplaySnapshot(page); | ||
| expect(secondSession.session?.sampled).toBe('buffer'); | ||
| expect(secondSession.recordingMode).toBe('buffer'); | ||
| expect(secondSession.session?.id).not.toBe(firstSessionId); | ||
| expect(secondSession.session?.segmentId).toBe(0); | ||
| }, | ||
| ); | ||
|
|
||
| sentryTest( | ||
| 'marks session as dirty immediately when error is sampled in buffer mode', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipReplayTest() || browserName === 'webkit') { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
| await page.goto(url); | ||
|
|
||
| // Wait for replay to initialize | ||
| await new Promise(resolve => setTimeout(resolve, 100)); | ||
|
|
||
| // Verify initial state - buffer mode, not sampled | ||
| const initialSession = await getReplaySnapshot(page); | ||
| expect(initialSession.recordingMode).toBe('buffer'); | ||
| expect(initialSession.session?.sampled).toBe('buffer'); | ||
| expect(initialSession.session?.segmentId).toBe(0); | ||
|
|
||
| // Trigger error which should immediately mark session as sampled | ||
| const reqErrorPromise = waitForErrorRequest(page); | ||
| await page.locator('#error1').click(); | ||
|
|
||
| const duringErrorProcessing = await getReplaySnapshot(page); | ||
| expect(duringErrorProcessing.session?.sampled).toBe('buffer'); | ||
| expect(duringErrorProcessing.session?.dirty).toBe(true); | ||
| expect(duringErrorProcessing.recordingMode).toBe('buffer'); // Still in buffer recording mode | ||
|
|
||
| await reqErrorPromise; | ||
|
|
||
| // After error is sent, verify state is still correct | ||
| const afterError = await getReplaySnapshot(page); | ||
| expect(afterError.session?.sampled).toBe('buffer'); | ||
| expect(afterError.recordingMode).toBe('session'); | ||
| expect(afterError.session?.dirty).toBe(false); | ||
|
|
||
| // Verify the session was persisted to sessionStorage (if sticky sessions enabled) | ||
| const sessionData = await page.evaluate(() => { | ||
| const sessionKey = 'sentryReplaySession'; | ||
| const data = sessionStorage.getItem(sessionKey); | ||
| return data ? JSON.parse(data) : null; | ||
| }); | ||
|
|
||
| expect(sessionData).toBeDefined(); | ||
| expect(sessionData.sampled).toBe('buffer'); | ||
| expect(sessionData.dirty).toBe(false); | ||
| }, | ||
| ); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.