-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(replay): Allow to treeshake & configure compression worker URL (#…
…9409) This PR does two things: 1. Allow to configure a `workerUrl` in replay config, which is expected to be an URL of a self-hosted worker script. a. Added an example worker script, which is a built version of the pako-based compression worker a. Users can basically host this file themselves and point to it in `workerUrl`, as long as it is on the same origin as the website itself. a. We can eventually document this in docs 1. Allows to configure `__SENTRY_EXCLUDE_REPLAY_WORKER__` in your build to strip the default included web worker. You can configure this if you're disabling compression anyhow, or if you want to configure a custom web worker as in the above step. Fixes #6739, and allows to reduce bundle size further. Once merged/released we can also add this to the bundler plugins `bundleSizeOptimizations` options. Note that we _do not recommend_ to disable the web worker completely. We only recommend to tree shake the worker code if you provide a custom worker URL - else, replay payloads will not be compressed, resulting in much larger payloads sent over the network, which is bad for your applications performance. Also note that when providing a custom worker, it is your own responsibility to keep it up to date - we try to keep the worker interface stable, and the worker is generally not updated often, but you should still check regularly when updating the SDK if the example worker has changed. --------- Co-authored-by: Billy Vong <[email protected]>
- Loading branch information
Showing
19 changed files
with
4,484 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
6 changes: 0 additions & 6 deletions
6
packages/browser-integration-tests/suites/replay/compression/subject.js
This file was deleted.
Oops, something went wrong.
This file contains 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
18 changes: 18 additions & 0 deletions
18
packages/browser-integration-tests/suites/replay/compressionDisabled/init.js
This file contains 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 = new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
useCompression: false, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/replay/compressionDisabled/template.html
This file contains 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,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="go-background">New Tab</button> | ||
</body> | ||
</html> |
52 changes: 52 additions & 0 deletions
52
packages/browser-integration-tests/suites/replay/compressionDisabled/test.ts
This file contains 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,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"'); | ||
}, | ||
); |
19 changes: 19 additions & 0 deletions
19
packages/browser-integration-tests/suites/replay/compressionWorkerUrl/init.js
This file contains 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,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://[email protected]/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/replay/compressionWorkerUrl/template.html
This file contains 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,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="go-background">New Tab</button> | ||
</body> | ||
</html> |
66 changes: 66 additions & 0 deletions
66
packages/browser-integration-tests/suites/replay/compressionWorkerUrl/test.ts
This file contains 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,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"'); | ||
}, | ||
); |
This file contains 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
This file contains 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
Oops, something went wrong.