-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(replay): Use session.started
for min/max duration check
#8617
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
23 changes: 23 additions & 0 deletions
23
packages/browser-integration-tests/suites/replay/maxReplayDuration/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,23 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); | ||
|
||
window.Replay._replay.timeouts = { | ||
sessionIdlePause: 1000, // this is usually 5min, but we want to test this with shorter times | ||
sessionIdleExpire: 2000, // this is usually 15min, but we want to test this with shorter times | ||
maxSessionLife: 2000, // default: 60min | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/browser-integration-tests/suites/replay/maxReplayDuration/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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button onclick="console.log('Test log 1')" id="button1">Click me</button> | ||
<button onclick="console.log('Test log 2')" id="button2">Click me</button> | ||
</body> | ||
</html> |
60 changes: 60 additions & 0 deletions
60
packages/browser-integration-tests/suites/replay/maxReplayDuration/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,60 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getExpectedReplayEvent } from '../../../utils/replayEventTemplates'; | ||
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; | ||
|
||
const SESSION_MAX_AGE = 2000; | ||
|
||
sentryTest('keeps track of max duration across reloads', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
const reqPromise1 = waitForReplayRequest(page, 1); | ||
|
||
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 new Promise(resolve => setTimeout(resolve, SESSION_MAX_AGE / 2)); | ||
|
||
await page.reload(); | ||
await page.click('#button1'); | ||
|
||
// After the second reload, we should have a new session (because we exceeded max age) | ||
const reqPromise3 = waitForReplayRequest(page, 0); | ||
|
||
await new Promise(resolve => setTimeout(resolve, SESSION_MAX_AGE / 2 + 100)); | ||
|
||
void page.click('#button1'); | ||
await page.evaluate(`Object.defineProperty(document, 'visibilityState', { | ||
configurable: true, | ||
get: function () { | ||
return 'hidden'; | ||
}, | ||
}); | ||
document.dispatchEvent(new Event('visibilitychange'));`); | ||
|
||
const replayEvent0 = getReplayEvent(await reqPromise0); | ||
expect(replayEvent0).toEqual(getExpectedReplayEvent({})); | ||
|
||
const replayEvent1 = getReplayEvent(await reqPromise1); | ||
expect(replayEvent1).toEqual( | ||
getExpectedReplayEvent({ | ||
segment_id: 1, | ||
}), | ||
); | ||
|
||
const replayEvent3 = getReplayEvent(await reqPromise3); | ||
expect(replayEvent3).toEqual(getExpectedReplayEvent({})); | ||
}); |
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
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.
Does this test fail without the new changes?
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.
No, sadly it does not 😬 I think it is because it still triggers the session refresh, as it should, this is kind of the root cause somewhere that this is under some (?) circumstances not happening. This change should be good/better anyhow, I'd say. And with the improved logging, we maybe get closer to the root of this!