Skip to content

Commit 1e7cf79

Browse files
authored
Merge branch 'develop' into steve/windows-rewrite-frames
2 parents deb3f39 + 6bd2637 commit 1e7cf79

File tree

9 files changed

+45
-34
lines changed

9 files changed

+45
-34
lines changed

packages/replay/src/eventBuffer/EventBufferArray.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,8 @@ export class EventBufferArray implements EventBuffer {
2424
}
2525

2626
/** @inheritdoc */
27-
public async addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<AddEventResult> {
28-
if (isCheckout) {
29-
this.events = [event];
30-
return;
31-
}
32-
27+
public async addEvent(event: RecordingEvent): Promise<AddEventResult> {
3328
this.events.push(event);
34-
return;
3529
}
3630

3731
/** @inheritdoc */
@@ -46,6 +40,11 @@ export class EventBufferArray implements EventBuffer {
4640
});
4741
}
4842

43+
/** @inheritdoc */
44+
public clear(): void {
45+
this.events = [];
46+
}
47+
4948
/** @inheritdoc */
5049
public getEarliestTimestamp(): number | null {
5150
const timestamp = this.events.map(event => event.timestamp).sort()[0];

packages/replay/src/eventBuffer/EventBufferCompressionWorker.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@ export class EventBufferCompressionWorker implements EventBuffer {
4242
*
4343
* Returns true if event was successfuly received and processed by worker.
4444
*/
45-
public async addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<AddEventResult> {
46-
if (isCheckout) {
47-
// This event is a checkout, make sure worker buffer is cleared before
48-
// proceeding.
49-
await this._clear();
50-
}
51-
45+
public addEvent(event: RecordingEvent): Promise<AddEventResult> {
5246
const timestamp = timestampToMs(event.timestamp);
5347
if (!this._earliestTimestamp || timestamp < this._earliestTimestamp) {
5448
this._earliestTimestamp = timestamp;
@@ -64,6 +58,13 @@ export class EventBufferCompressionWorker implements EventBuffer {
6458
return this._finishRequest();
6559
}
6660

61+
/** @inheritdoc */
62+
public clear(): void {
63+
this._earliestTimestamp = null;
64+
// We do not wait on this, as we assume the order of messages is consistent for the worker
65+
void this._worker.postMessage('clear');
66+
}
67+
6768
/** @inheritdoc */
6869
public getEarliestTimestamp(): number | null {
6970
return this._earliestTimestamp;
@@ -86,10 +87,4 @@ export class EventBufferCompressionWorker implements EventBuffer {
8687

8788
return response;
8889
}
89-
90-
/** Clear any pending events from the worker. */
91-
private _clear(): Promise<void> {
92-
this._earliestTimestamp = null;
93-
return this._worker.postMessage('clear');
94-
}
9590
}

packages/replay/src/eventBuffer/EventBufferProxy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export class EventBufferProxy implements EventBuffer {
3535
this._compression.destroy();
3636
}
3737

38+
/** @inheritdoc */
39+
public clear(): void {
40+
return this._used.clear();
41+
}
42+
3843
/** @inheritdoc */
3944
public getEarliestTimestamp(): number | null {
4045
return this._used.getEarliestTimestamp();
@@ -45,8 +50,8 @@ export class EventBufferProxy implements EventBuffer {
4550
*
4651
* Returns true if event was successfully added.
4752
*/
48-
public addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<AddEventResult> {
49-
return this._used.addEvent(event, isCheckout);
53+
public addEvent(event: RecordingEvent): Promise<AddEventResult> {
54+
return this._used.addEvent(event);
5055
}
5156

5257
/** @inheritDoc */

packages/replay/src/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,17 @@ export interface EventBuffer {
446446
*/
447447
destroy(): void;
448448

449+
/**
450+
* Clear the event buffer.
451+
*/
452+
clear(): void;
453+
449454
/**
450455
* Add an event to the event buffer.
451-
* `isCheckout` is true if this is either the very first event, or an event triggered by `checkoutEveryNms`.
452456
*
453457
* Returns a promise that resolves if the event was successfully added, else rejects.
454458
*/
455-
addEvent(event: RecordingEvent, isCheckout?: boolean): Promise<AddEventResult>;
459+
addEvent(event: RecordingEvent): Promise<AddEventResult>;
456460

457461
/**
458462
* Clears and returns the contents of the buffer.

packages/replay/src/util/addEvent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export async function addEvent(
3434
}
3535

3636
try {
37-
return await replay.eventBuffer.addEvent(event, isCheckout);
37+
if (isCheckout) {
38+
replay.eventBuffer.clear();
39+
}
40+
41+
return await replay.eventBuffer.addEvent(event);
3842
} catch (error) {
3943
__DEBUG_BUILD__ && logger.error(error);
4044
await replay.stop('addEvent');

packages/replay/test/unit/eventBuffer/EventBufferArray.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe('Unit | eventBuffer | EventBufferArray', () => {
2222
buffer.addEvent(TEST_EVENT);
2323
buffer.addEvent(TEST_EVENT);
2424

25-
buffer.addEvent(TEST_EVENT, true);
25+
// clear() is called by addEvent when isCheckout is true
26+
buffer.clear();
27+
buffer.addEvent(TEST_EVENT);
2628
const result = await buffer.finish();
2729

2830
expect(result).toEqual(JSON.stringify([TEST_EVENT]));

packages/replay/test/unit/eventBuffer/EventBufferCompressionWorker.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ describe('Unit | eventBuffer | EventBufferCompressionWorker', () => {
4242
await buffer.addEvent(TEST_EVENT);
4343
await buffer.addEvent(TEST_EVENT);
4444

45-
// This should clear previous buffer
46-
await buffer.addEvent({ ...TEST_EVENT, type: 2 }, true);
45+
// clear() is called by addEvent when isCheckout is true
46+
buffer.clear();
47+
await buffer.addEvent({ ...TEST_EVENT, type: 2 });
4748

4849
const result = await buffer.finish();
4950
expect(result).toBeInstanceOf(Uint8Array);
@@ -135,7 +136,7 @@ describe('Unit | eventBuffer | EventBufferCompressionWorker', () => {
135136
// Ensure worker is ready
136137
await buffer.ensureWorkerIsLoaded();
137138

138-
await buffer.addEvent({ data: { o: 1 }, timestamp: BASE_TIMESTAMP, type: 3 }, true);
139+
await buffer.addEvent({ data: { o: 1 }, timestamp: BASE_TIMESTAMP, type: 3 });
139140
await buffer.addEvent({ data: { o: 2 }, timestamp: BASE_TIMESTAMP, type: 3 });
140141

141142
// @ts-ignore Mock this private so it triggers an error

packages/tracing-internal/src/browser/request.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export function fetchCallback(
195195
data: {
196196
...handlerData.fetchData,
197197
type: 'fetch',
198+
'http.method': handlerData.fetchData.method,
198199
},
199200
description: `${handlerData.fetchData.method} ${handlerData.fetchData.url}`,
200201
op: 'http.client',
@@ -334,7 +335,7 @@ export function xhrCallback(
334335
data: {
335336
...sentryXhrData.data,
336337
type: 'xhr',
337-
method: sentryXhrData.method,
338+
'http.method': sentryXhrData.method,
338339
url: sentryXhrData.url,
339340
},
340341
description: `${sentryXhrData.method} ${sentryXhrData.url}`,

packages/tracing-internal/test/browser/request.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('callbacks', () => {
7474

7575
const fetchSpan = {
7676
data: {
77-
method: 'GET',
77+
'http.method': 'GET',
7878
url: 'http://dogs.are.great/',
7979
type: 'fetch',
8080
},
@@ -156,7 +156,7 @@ describe('callbacks', () => {
156156
expect(newSpan).toBeDefined();
157157
expect(newSpan).toBeInstanceOf(Span);
158158
expect(newSpan.data).toEqual({
159-
method: 'GET',
159+
'http.method': 'GET',
160160
type: 'fetch',
161161
url: 'http://dogs.are.great/',
162162
});
@@ -220,7 +220,7 @@ describe('callbacks', () => {
220220

221221
const xhrSpan = {
222222
data: {
223-
method: 'GET',
223+
'http.method': 'GET',
224224
url: 'http://dogs.are.great/',
225225
type: 'xhr',
226226
},
@@ -295,7 +295,7 @@ describe('callbacks', () => {
295295

296296
expect(newSpan).toBeInstanceOf(Span);
297297
expect(newSpan.data).toEqual({
298-
method: 'GET',
298+
'http.method': 'GET',
299299
type: 'xhr',
300300
url: 'http://dogs.are.great/',
301301
});

0 commit comments

Comments
 (0)