-
-
Couldn't load subscription status.
- Fork 1.7k
fix(replay): Start replay in afterAllSetup instead of next tick
#12709
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| window.doSomethingWrong(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; | ||
| import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
|
||
| sentryTest('should capture a replay & attach an error', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipReplayTest()) { | ||
| 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 req = waitForReplayRequest(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| const reqError = await waitForErrorRequestOnUrl(page, url); | ||
|
|
||
| const errorEventData = envelopeRequestParser(reqError); | ||
| expect(errorEventData.exception?.values?.length).toBe(1); | ||
| expect(errorEventData.exception?.values?.[0]?.value).toContain('window.doSomethingWrong is not a function'); | ||
|
|
||
| const eventData = getReplayEvent(await req); | ||
|
|
||
| expect(eventData).toBeDefined(); | ||
| expect(eventData.segment_id).toBe(0); | ||
|
|
||
| expect(errorEventData.tags?.replayId).toEqual(eventData.replay_id); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,7 @@ Sentry.onLoad(function () { | |
| useCompression: false, | ||
| }), | ||
| ], | ||
|
|
||
| replaysSessionSampleRate: 1, | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| Sentry.onLoad(function () { | ||
| Sentry.init({}); | ||
| Sentry.init({ | ||
| replaysSessionSampleRate: 1, | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| window.doSomethingWrong(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers'; | ||
| import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
|
||
| sentryTest( | ||
| '[error-mode] should capture error that happens immediately after init', | ||
| async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipReplayTest()) { | ||
| 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 req = waitForReplayRequest(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| const reqError = await waitForErrorRequestOnUrl(page, url); | ||
|
|
||
| const errorEventData = envelopeRequestParser(reqError); | ||
| expect(errorEventData.exception?.values?.length).toBe(1); | ||
| expect(errorEventData.exception?.values?.[0]?.value).toContain('window.doSomethingWrong is not a function'); | ||
|
|
||
| const eventData = getReplayEvent(await req); | ||
|
|
||
| expect(eventData).toBeDefined(); | ||
| expect(eventData.segment_id).toBe(0); | ||
|
|
||
| expect(errorEventData.tags?.replayId).toEqual(eventData.replay_id); | ||
| }, | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { getClient } from '@sentry/core'; | ||
| import type { Event } from '@sentry/types'; | ||
|
|
||
| import { REPLAY_EVENT_NAME, SESSION_IDLE_EXPIRE_DURATION } from '../../../src/constants'; | ||
|
|
@@ -133,8 +134,8 @@ describe('Integration | coreHandlers | handleGlobalEvent', () => { | |
|
|
||
| it('tags errors and transactions with replay id for session samples', async () => { | ||
| const { replay, integration } = await resetSdkMock({}); | ||
| // @ts-expect-error protected but ok to use for testing | ||
| integration._initialize(); | ||
| integration['_initialize'](getClient()!); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. omg this syntax 😅 Not wrong at all, just JS/TS 🙄 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it is definitely weird, but I prefer this over having to do |
||
|
|
||
| const transaction = Transaction(); | ||
| const error = Error(); | ||
| expect(handleGlobalEventListener(replay)(transaction, {})).toEqual( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,12 +61,8 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true } | |
| _initialized = value; | ||
| } | ||
|
|
||
| public setupOnce(): void { | ||
| // do nothing | ||
| } | ||
|
|
||
| public initialize(): void { | ||
| return super._initialize(); | ||
| public afterAllSetup(): void { | ||
| // do nothing, we need to manually initialize this | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -76,7 +72,7 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true } | |
| ...replayOptions, | ||
| }); | ||
|
|
||
| init({ | ||
| const client = init({ | ||
| ...getDefaultClientOptions(), | ||
| dsn: 'https://[email protected]/1', | ||
| autoSessionTracking: false, | ||
|
|
@@ -86,14 +82,14 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true } | |
| replaysOnErrorSampleRate: 0.0, | ||
| ...sentryOptions, | ||
| integrations: [replayIntegration], | ||
| }); | ||
| })!; | ||
|
|
||
| // Instead of `setupOnce`, which is tricky to test, we call this manually here | ||
| replayIntegration['_setup'](); | ||
| // Instead of `afterAllSetup`, which is tricky to test, we call this manually here | ||
| replayIntegration['_setup'](client); | ||
|
|
||
| if (autoStart) { | ||
| // Only exists in our mock | ||
| replayIntegration.initialize(); | ||
| replayIntegration['_initialize'](client); | ||
| } | ||
|
|
||
| const replay = replayIntegration['_replay']!; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove this now?