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
feat(replay): Allow to treeshake & configure compression worker URL#9409
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
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| 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 = new Sentry.Replay({ | ||
| flushMinDelay: 200, | ||
| flushMaxDelay: 200, | ||
| minReplayDuration: 0, | ||
| useCompression: false, | ||
| }); | ||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| sampleRate: 0, | ||
| replaysSessionSampleRate: 1.0, | ||
| replaysOnErrorSampleRate: 0.0, | ||
| integrations: [window.Replay], | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button id="go-background">New Tab</button> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates'; | ||
| import { | ||
| getFullRecordingSnapshots, | ||
| getReplayEvent, | ||
| replayEnvelopeIsCompressed, | ||
| shouldSkipReplayTest, | ||
| waitForReplayRequest, | ||
| } from '../../../utils/replayHelpers'; | ||
| sentryTest( | ||
| 'replay recording should allow to disable compression', | ||
| async ({ getLocalTestPath, page, forceFlushReplay }) => { | ||
| if (shouldSkipReplayTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
| const reqPromise0 = waitForReplayRequest(page, 0); | ||
| 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 getLocalTestPath({ testDir: __dirname }); | ||
| await page.goto(url); | ||
| await forceFlushReplay(); | ||
| const req0 = await reqPromise0; | ||
| const replayEvent0 = getReplayEvent(req0); | ||
| expect(replayEvent0).toEqual(getExpectedReplayEvent()); | ||
| expect(replayEnvelopeIsCompressed(req0)).toEqual(false); | ||
| const snapshots = getFullRecordingSnapshots(req0); | ||
| expect(snapshots.length).toEqual(1); | ||
| const stringifiedSnapshot = JSON.stringify(snapshots[0]); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"body"'); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"html"'); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"button"'); | ||
| expect(stringifiedSnapshot).toContain('"textContent":"*** ***"'); | ||
| expect(stringifiedSnapshot).toContain('"id":"go-background"'); | ||
| }, | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| window.Sentry = Sentry; | ||
| window.Replay = new Sentry.Replay({ | ||
| flushMinDelay: 200, | ||
| flushMaxDelay: 200, | ||
| minReplayDuration: 0, | ||
| useCompression: true, | ||
| workerUrl: `${window.location.origin}/my-test-worker.js`, | ||
| }); | ||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| sampleRate: 0, | ||
| replaysSessionSampleRate: 1.0, | ||
| replaysOnErrorSampleRate: 0.0, | ||
| integrations: [window.Replay], | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button id="go-background">New Tab</button> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { sentryTest, TEST_HOST } from '../../../utils/fixtures'; | ||
| import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates'; | ||
| import { | ||
| getFullRecordingSnapshots, | ||
| getReplayEvent, | ||
| replayEnvelopeIsCompressed, | ||
| shouldSkipReplayTest, | ||
| waitForReplayRequest, | ||
| } from '../../../utils/replayHelpers'; | ||
| sentryTest( | ||
| 'replay recording should be compressed if using custom workerUrl', | ||
| async ({ getLocalTestUrl, page, forceFlushReplay }) => { | ||
| if (shouldSkipReplayTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
| const reqPromise0 = waitForReplayRequest(page, 0); | ||
| 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 }); | ||
| let customCompressCalled = 0; | ||
| // Ensure to register this _after_ getLocalTestUrl is called, as that also registers a default route for TEST_HOST | ||
| await page.route(`${TEST_HOST}/my-test-worker.js`, route => { | ||
| const filePath = path.resolve(__dirname, '../../../../replay-worker/examples/worker.min.js'); | ||
| customCompressCalled++; | ||
| return fs.existsSync(filePath) ? route.fulfill({ path: filePath }) : route.continue(); | ||
| }); | ||
| await page.goto(url); | ||
| await forceFlushReplay(); | ||
| const req0 = await reqPromise0; | ||
| const replayEvent0 = getReplayEvent(req0); | ||
| expect(replayEvent0).toEqual(getExpectedReplayEvent()); | ||
| expect(replayEnvelopeIsCompressed(req0)).toEqual(true); | ||
| expect(customCompressCalled).toBe(1); | ||
| const snapshots = getFullRecordingSnapshots(req0); | ||
| expect(snapshots.length).toEqual(1); | ||
| const stringifiedSnapshot = JSON.stringify(snapshots[0]); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"body"'); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"html"'); | ||
| expect(stringifiedSnapshot).toContain('"tagName":"button"'); | ||
| expect(stringifiedSnapshot).toContain('"textContent":"*** ***"'); | ||
| expect(stringifiedSnapshot).toContain('"id":"go-background"'); | ||
| }, | ||
| ); |
Uh oh!
There was an error while loading. Please reload this page.
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.
I also added a check to actually test that we are sending a compressed payload 😅