-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test: Fix flaky errorsInSession replay test #7309
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
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
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { RecordingEvent, ReplayContainer } from '@sentry/replay/build/npm/types/types'; | ||
import type { Breadcrumb, Event, ReplayEvent } from '@sentry/types'; | ||
import pako from 'pako'; | ||
import type { Page, Request } from 'playwright'; | ||
import type { Page, Request, Response } from 'playwright'; | ||
|
||
import { envelopeRequestParser } from './helpers'; | ||
|
||
|
@@ -37,8 +37,10 @@ type SnapshotNode = { | |
* @param segmentId the segment_id of the replay event | ||
* @returns | ||
*/ | ||
export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Request> { | ||
return page.waitForRequest(req => { | ||
export function waitForReplayRequest(page: Page, segmentId?: number): Promise<Response> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually wait on a response here now, as that may be a bit better/more expected timing. |
||
return page.waitForResponse(res => { | ||
const req = res.request(); | ||
|
||
const postData = req.postData(); | ||
if (!postData) { | ||
return false; | ||
|
@@ -78,7 +80,8 @@ export async function getReplaySnapshot(page: Page): Promise<ReplayContainer> { | |
|
||
export const REPLAY_DEFAULT_FLUSH_MAX_DELAY = 5_000; | ||
|
||
export function getReplayEvent(replayRequest: Request): ReplayEvent { | ||
export function getReplayEvent(resOrReq: Request | Response): ReplayEvent { | ||
const replayRequest = getRequest(resOrReq); | ||
const event = envelopeRequestParser(replayRequest); | ||
if (!isReplayEvent(event)) { | ||
throw new Error('Request is not a replay event'); | ||
|
@@ -103,7 +106,8 @@ type RecordingContent = { | |
* @param replayRequest | ||
* @returns an object containing the replay breadcrumbs and performance spans | ||
*/ | ||
export function getCustomRecordingEvents(replayRequest: Request): CustomRecordingContent { | ||
export function getCustomRecordingEvents(resOrReq: Request | Response): CustomRecordingContent { | ||
const replayRequest = getRequest(resOrReq); | ||
const recordingEvents = getDecompressedRecordingEvents(replayRequest); | ||
|
||
const breadcrumbs = getReplayBreadcrumbs(recordingEvents); | ||
|
@@ -128,21 +132,25 @@ function getReplayPerformanceSpans(recordingEvents: RecordingEvent[]): Performan | |
.map(data => data.payload) as PerformanceSpan[]; | ||
} | ||
|
||
export function getFullRecordingSnapshots(replayRequest: Request): RecordingSnapshot[] { | ||
export function getFullRecordingSnapshots(resOrReq: Request | Response): RecordingSnapshot[] { | ||
const replayRequest = getRequest(resOrReq); | ||
const events = getDecompressedRecordingEvents(replayRequest) as RecordingEvent[]; | ||
return events.filter(event => event.type === 2).map(event => event.data as RecordingSnapshot); | ||
} | ||
|
||
function getIncrementalRecordingSnapshots(replayRequest: Request): RecordingSnapshot[] { | ||
function getIncrementalRecordingSnapshots(resOrReq: Request | Response): RecordingSnapshot[] { | ||
const replayRequest = getRequest(resOrReq); | ||
const events = getDecompressedRecordingEvents(replayRequest) as RecordingEvent[]; | ||
return events.filter(event => event.type === 3).map(event => event.data as RecordingSnapshot); | ||
} | ||
|
||
function getDecompressedRecordingEvents(replayRequest: Request): RecordingEvent[] { | ||
function getDecompressedRecordingEvents(resOrReq: Request | Response): RecordingEvent[] { | ||
const replayRequest = getRequest(resOrReq); | ||
return replayEnvelopeRequestParser(replayRequest, 5) as RecordingEvent[]; | ||
} | ||
|
||
export function getReplayRecordingContent(replayRequest: Request): RecordingContent { | ||
export function getReplayRecordingContent(resOrReq: Request | Response): RecordingContent { | ||
const replayRequest = getRequest(resOrReq); | ||
const fullSnapshots = getFullRecordingSnapshots(replayRequest); | ||
const incrementalSnapshots = getIncrementalRecordingSnapshots(replayRequest); | ||
const customEvents = getCustomRecordingEvents(replayRequest); | ||
|
@@ -255,3 +263,9 @@ function normalizeNumberAttribute(num: number): string { | |
|
||
return `[${stepCount * step}-${(stepCount + 1) * step}]`; | ||
} | ||
|
||
/** Get a request from either a request or a response */ | ||
function getRequest(resOrReq: Request | Response): Request { | ||
// @ts-ignore we check this | ||
return typeof resOrReq.request === 'function' ? (resOrReq as Response).request() : (resOrReq as Request); | ||
} |
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.
This could probably sometimes lead to a second flush, which we didn't actually want/need. It will flush on page visit anyhow!