-
-
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 configure
beforeErrorSampling
(#9470)
This adds a new option to `new Replay()` which allows to ignore certain errors for error-based sampling: ```js new Replay({ beforeErrorSampling: (event) => !event.message.includes('ignore me') }); ``` When returning `false` from this callback, the event will not trigger an error-based sampling. Note that returning `true` there does not mean this will 100% be sampled, but just that it will check the `replaysOnErrorSampleRate`. The purpose of this callback is to be able to ignore certain groups of errors from triggering an error-based replay at all. Closes #9413 Related to #8462 (not 100% but partially)
- Loading branch information
Showing
6 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/browser-integration-tests/suites/replay/errors/beforeErrorSampling/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, | ||
beforeErrorSampling: event => !event.message.includes('[drop]'), | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 1, | ||
replaysSessionSampleRate: 0.0, | ||
replaysOnErrorSampleRate: 1.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/browser-integration-tests/suites/replay/errors/beforeErrorSampling/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,38 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getReplaySnapshot, shouldSkipReplayTest, waitForReplayRunning } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest( | ||
'[error-mode] should not flush if error event is ignored in beforeErrorSampling', | ||
async ({ getLocalTestPath, page, browserName, forceFlushReplay }) => { | ||
// Skipping this in webkit because it is flakey there | ||
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 getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await waitForReplayRunning(page); | ||
|
||
await page.click('#drop'); | ||
await forceFlushReplay(); | ||
|
||
expect(await getReplaySnapshot(page)).toEqual( | ||
expect.objectContaining({ | ||
_isEnabled: true, | ||
_isPaused: false, | ||
recordingMode: 'buffer', | ||
}), | ||
); | ||
}, | ||
); |
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
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