Skip to content

Commit 26840af

Browse files
committed
ref(replay): Make addMemoryEntry and createPerformanceSpans to sync
1 parent 653d816 commit 26840af

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

packages/replay/src/coreHandlers/handleFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function handleFetchSpanListener(replay: ReplayContainer): (handlerData:
6161
}
6262

6363
replay.addUpdate(() => {
64-
void createPerformanceSpans(replay, [result]);
64+
createPerformanceSpans(replay, [result]);
6565
// Returning true will cause `addUpdate` to not flush
6666
// We do not want network requests to cause a flush. This will prevent
6767
// recurring/polling requests from keeping the replay session alive.

packages/replay/src/coreHandlers/handleHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function handleHistorySpanListener(replay: ReplayContainer): (handlerData
4343
replay.triggerUserActivity();
4444

4545
replay.addUpdate(() => {
46-
void createPerformanceSpans(replay, [result]);
46+
createPerformanceSpans(replay, [result]);
4747
// Returning false to flush
4848
return false;
4949
});

packages/replay/src/coreHandlers/handleXhr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function handleXhrSpanListener(replay: ReplayContainer): (handlerData: Xh
8080
}
8181

8282
replay.addUpdate(() => {
83-
void createPerformanceSpans(replay, [result]);
83+
createPerformanceSpans(replay, [result]);
8484
// Returning true will cause `addUpdate` to not flush
8585
// We do not want network requests to cause a flush. This will prevent
8686
// recurring/polling requests from keeping the replay session alive.

packages/replay/src/replay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,12 @@ export class ReplayContainer implements ReplayContainerInterface {
696696
* Observed performance events are added to `this.performanceEvents`. These
697697
* are included in the replay event before it is finished and sent to Sentry.
698698
*/
699-
addPerformanceEntries(): Promise<void[]> {
699+
addPerformanceEntries(): void {
700700
// Copy and reset entries before processing
701701
const entries = [...this.performanceEvents];
702702
this.performanceEvents = [];
703703

704-
return createPerformanceSpans(this, createPerformanceEntries(entries));
704+
createPerformanceSpans(this, createPerformanceEntries(entries));
705705
}
706706

707707
/**

packages/replay/src/util/addMemoryEntry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { createPerformanceSpans } from './createPerformanceSpans';
66
* Create a "span" for the total amount of memory being used by JS objects
77
* (including v8 internal objects).
88
*/
9-
export function addMemoryEntry(replay: ReplayContainer): Promise<void[]> | undefined {
9+
export function addMemoryEntry(replay: ReplayContainer): void {
1010
// window.performance.memory is a non-standard API and doesn't work on all browsers, so we try-catch this
1111
try {
12-
return createPerformanceSpans(replay, [
12+
createPerformanceSpans(replay, [
1313
// @ts-ignore memory doesn't exist on type Performance as the API is non-standard (we check that it exists above)
1414
createMemoryEntry(WINDOW.performance.memory),
1515
]);
1616
} catch (error) {
17-
return;
17+
// Do nothing
1818
}
1919
}

packages/replay/src/util/createPerformanceSpans.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ import { addEvent } from './addEvent';
77
/**
88
* Create a "span" for each performance entry. The parent transaction is `this.replayEvent`.
99
*/
10-
export function createPerformanceSpans(replay: ReplayContainer, entries: ReplayPerformanceEntry[]): Promise<void[]> {
11-
return Promise.all(
12-
entries.map(({ type, start, end, name, data }) =>
13-
addEvent(replay, {
14-
type: EventType.Custom,
15-
timestamp: start,
16-
data: {
17-
tag: 'performanceSpan',
18-
payload: {
19-
op: type,
20-
description: name,
21-
startTimestamp: start,
22-
endTimestamp: end,
23-
data,
24-
},
10+
export function createPerformanceSpans(replay: ReplayContainer, entries: ReplayPerformanceEntry[]): void {
11+
entries.map(({ type, start, end, name, data }) =>
12+
addEvent(replay, {
13+
type: EventType.Custom,
14+
timestamp: start,
15+
data: {
16+
tag: 'performanceSpan',
17+
payload: {
18+
op: type,
19+
description: name,
20+
startTimestamp: start,
21+
endTimestamp: end,
22+
data,
2523
},
26-
}),
27-
),
24+
},
25+
}),
2826
);
2927
}

packages/replay/test/unit/flush.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ it('long first flush enqueues following events', async () => {
179179
});
180180

181181
// Add this to test that segment ID increases
182-
mockAddPerformanceEntries.mockImplementationOnce(async () => {
183-
return createPerformanceSpans(
182+
mockAddPerformanceEntries.mockImplementationOnce(() => {
183+
createPerformanceSpans(
184184
replay,
185185
createPerformanceEntries([
186186
{

0 commit comments

Comments
 (0)