Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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()!); | ||
Member 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 🙄 😆 MemberAuthor 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( | ||
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?