Skip to content

Commit 55189fa

Browse files
committed
ref(browser): Refactor browser integrations to use processEvent
1 parent 3ae909b commit 55189fa

File tree

3 files changed

+44
-49
lines changed

3 files changed

+44
-49
lines changed

packages/browser/src/integrations/dedupe.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Event, EventProcessor, Exception, Hub, Integration, StackFrame } from '@sentry/types';
1+
import type { Event, Exception, Integration, StackFrame } from '@sentry/types';
22
import { logger } from '@sentry/utils';
33

44
/** Deduplication filter */
@@ -22,36 +22,32 @@ export class Dedupe implements Integration {
2222
this.name = Dedupe.id;
2323
}
2424

25+
/** @inheritDoc */
26+
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
27+
// noop
28+
}
29+
2530
/**
2631
* @inheritDoc
2732
*/
28-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
29-
const eventProcessor: EventProcessor = currentEvent => {
30-
// We want to ignore any non-error type events, e.g. transactions or replays
31-
// These should never be deduped, and also not be compared against as _previousEvent.
32-
if (currentEvent.type) {
33-
return currentEvent;
34-
}
33+
public processEvent(currentEvent: Event): Event | null {
34+
// We want to ignore any non-error type events, e.g. transactions or replays
35+
// These should never be deduped, and also not be compared against as _previousEvent.
36+
if (currentEvent.type) {
37+
return currentEvent;
38+
}
3539

36-
const self = getCurrentHub().getIntegration(Dedupe);
37-
if (self) {
38-
// Juuust in case something goes wrong
39-
try {
40-
if (_shouldDropEvent(currentEvent, self._previousEvent)) {
41-
__DEBUG_BUILD__ && logger.warn('Event dropped due to being a duplicate of previously captured event.');
42-
return null;
43-
}
44-
} catch (_oO) {
45-
return (self._previousEvent = currentEvent);
46-
}
47-
48-
return (self._previousEvent = currentEvent);
40+
// Juuust in case something goes wrong
41+
try {
42+
if (_shouldDropEvent(currentEvent, this._previousEvent)) {
43+
__DEBUG_BUILD__ && logger.warn('Event dropped due to being a duplicate of previously captured event.');
44+
return null;
4945
}
50-
return currentEvent;
51-
};
46+
} catch (_oO) {
47+
return (this._previousEvent = currentEvent);
48+
}
5249

53-
eventProcessor.id = this.name;
54-
addGlobalEventProcessor(eventProcessor);
50+
return (this._previousEvent = currentEvent);
5551
}
5652
}
5753

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
21
import type { Event, Integration } from '@sentry/types';
32

43
import { WINDOW } from '../helpers';
@@ -23,28 +22,28 @@ export class HttpContext implements Integration {
2322
* @inheritDoc
2423
*/
2524
public setupOnce(): void {
26-
addGlobalEventProcessor((event: Event) => {
27-
if (getCurrentHub().getIntegration(HttpContext)) {
28-
// if none of the information we want exists, don't bother
29-
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
30-
return event;
31-
}
32-
33-
// grab as much info as exists and add it to the event
34-
const url = (event.request && event.request.url) || (WINDOW.location && WINDOW.location.href);
35-
const { referrer } = WINDOW.document || {};
36-
const { userAgent } = WINDOW.navigator || {};
37-
38-
const headers = {
39-
...(event.request && event.request.headers),
40-
...(referrer && { Referer: referrer }),
41-
...(userAgent && { 'User-Agent': userAgent }),
42-
};
43-
const request = { ...event.request, ...(url && { url }), headers };
44-
45-
return { ...event, request };
46-
}
25+
// noop
26+
}
27+
28+
/** @inheritDoc */
29+
public processEvent(event: Event): Event {
30+
// if none of the information we want exists, don't bother
31+
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
4732
return event;
48-
});
33+
}
34+
35+
// grab as much info as exists and add it to the event
36+
const url = (event.request && event.request.url) || (WINDOW.location && WINDOW.location.href);
37+
const { referrer } = WINDOW.document || {};
38+
const { userAgent } = WINDOW.navigator || {};
39+
40+
const headers = {
41+
...(event.request && event.request.headers),
42+
...(referrer && { Referer: referrer }),
43+
...(userAgent && { 'User-Agent': userAgent }),
44+
};
45+
const request = { ...event.request, ...(url && { url }), headers };
46+
47+
return { ...event, request };
4948
}
5049
}

packages/browser/src/profiling/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class BrowserProfilingIntegration implements Integration {
3535
/**
3636
* @inheritDoc
3737
*/
38-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
38+
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
3939
this.getCurrentHub = getCurrentHub;
4040
const client = this.getCurrentHub().getClient() as BrowserClient;
4141

0 commit comments

Comments
 (0)