-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Add _experiments.ignoreMutations
option
#16816
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
dev-packages/browser-integration-tests/suites/replay/ignoreMutations/init.js
This file contains hidden or 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,21 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = Sentry.replayIntegration({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
useCompression: false, | ||
_experiments: { | ||
ignoreMutations: ['.moving'], | ||
}, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
26 changes: 26 additions & 0 deletions
26
dev-packages/browser-integration-tests/suites/replay/ignoreMutations/subject.js
This file contains hidden or 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,26 @@ | ||
function moveElement(el, remaining) { | ||
if (!remaining) { | ||
el.classList.remove('moving'); | ||
|
||
setTimeout(() => { | ||
el.style.transform = `translate(${remaining}0px, 0)`; | ||
el.classList.add('moved'); | ||
}); | ||
return; | ||
} | ||
|
||
el.style.transform = `translate(${remaining}0px, 0)`; | ||
|
||
setTimeout(() => { | ||
moveElement(el, remaining - 1); | ||
}, 10); | ||
} | ||
|
||
const el = document.querySelector('#mutation-target'); | ||
const btn = document.querySelector('#button-move'); | ||
|
||
btn.addEventListener('click', event => { | ||
el.classList.add('moving'); | ||
event.preventDefault(); | ||
moveElement(el, 20); | ||
}); |
11 changes: 11 additions & 0 deletions
11
dev-packages/browser-integration-tests/suites/replay/ignoreMutations/template.html
This file contains hidden or 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,11 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<div id="mutation-target" style="position: relative">This is moved around!</div> | ||
|
||
<button id="button-move" type="button">Move</button> | ||
</body> | ||
</html> |
65 changes: 65 additions & 0 deletions
65
dev-packages/browser-integration-tests/suites/replay/ignoreMutations/test.ts
This file contains hidden or 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,65 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { mutationData } from '@sentry-internal/rrweb-types'; | ||
import { sentryTest } from '../../../utils/fixtures'; | ||
import type { RecordingSnapshot } from '../../../utils/replayHelpers'; | ||
import { collectReplayRequests, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; | ||
|
||
sentryTest('allows to ignore mutations via `ignoreMutations` option', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
|
||
await page.goto(url); | ||
await reqPromise0; | ||
|
||
const requestsPromise = collectReplayRequests(page, recordingEvents => { | ||
const events = recordingEvents as (RecordingSnapshot & { data: mutationData })[]; | ||
return events.some(event => event.data.attributes?.some(attr => attr.attributes['class'] === 'moved')); | ||
}); | ||
|
||
page.locator('#button-move').click(); | ||
|
||
const requests = await requestsPromise; | ||
|
||
// All transform mutatinos are ignored and not captured | ||
const transformMutations = requests.replayRecordingSnapshots.filter( | ||
item => | ||
(item.data as mutationData)?.attributes?.some( | ||
attr => attr.attributes['style'] && attr.attributes['class'] !== 'moved', | ||
), | ||
); | ||
|
||
// Should capture the final class mutation | ||
const classMutations = requests.replayRecordingSnapshots.filter( | ||
item => (item.data as mutationData)?.attributes?.some(attr => attr.attributes['class']), | ||
); | ||
|
||
expect(transformMutations).toEqual([]); | ||
expect(classMutations).toEqual([ | ||
{ | ||
data: { | ||
adds: [], | ||
attributes: [ | ||
{ | ||
attributes: { | ||
class: 'moved', | ||
style: { | ||
transform: 'translate(0px, 0px)', | ||
}, | ||
}, | ||
id: expect.any(Number), | ||
}, | ||
], | ||
removes: [], | ||
source: expect.any(Number), | ||
texts: [], | ||
}, | ||
timestamp: 0, | ||
type: 3, | ||
}, | ||
]); | ||
}); |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
/** | ||
* Vendored in from @sentry-internal/rrweb. | ||
* | ||
* This is a copy of the function from rrweb, it is not nicely exported there. | ||
*/ | ||
export function closestElementOfNode(node: Node | null): HTMLElement | null { | ||
if (!node) { | ||
return null; | ||
} | ||
|
||
// Catch access to node properties to avoid Firefox "permission denied" errors | ||
try { | ||
const el: HTMLElement | null = node.nodeType === node.ELEMENT_NODE ? (node as HTMLElement) : node.parentElement; | ||
return el; | ||
} catch (error) { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the purpose of declaring the
el
constant here?Is it to make debugging easier? 🙂
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.
this is just vendored in from the rrweb implementation!