Skip to content

Commit a753bc4

Browse files
mydeac298lee
authored andcommitted
ref(core): Refactor InboundFilters integration to use processEvent (#9020)
This refactors core integrations to use `processEvent`.
1 parent bb469f9 commit a753bc4

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

packages/core/src/integrations/inboundfilters.ts

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

44
// "Script error." is hard coded into browsers for errors that it can't read.
@@ -48,23 +48,15 @@ export class InboundFilters implements Integration {
4848
/**
4949
* @inheritDoc
5050
*/
51-
public setupOnce(addGlobalEventProcessor: (processor: EventProcessor) => void, getCurrentHub: () => Hub): void {
52-
const eventProcess: EventProcessor = (event: Event) => {
53-
const hub = getCurrentHub();
54-
if (hub) {
55-
const self = hub.getIntegration(InboundFilters);
56-
if (self) {
57-
const client = hub.getClient();
58-
const clientOptions = client ? client.getOptions() : {};
59-
const options = _mergeOptions(self._options, clientOptions);
60-
return _shouldDropEvent(event, options) ? null : event;
61-
}
62-
}
63-
return event;
64-
};
51+
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
52+
// noop
53+
}
6554

66-
eventProcess.id = this.name;
67-
addGlobalEventProcessor(eventProcess);
55+
/** @inheritDoc */
56+
public processEvent(event: Event, _eventHint: EventHint, client: Client): Event | null {
57+
const clientOptions = client.getOptions();
58+
const options = _mergeOptions(this._options, clientOptions);
59+
return _shouldDropEvent(event, options) ? null : event;
6860
}
6961
}
7062

packages/core/test/lib/integrations/inboundfilters.test.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type { Event, EventProcessor } from '@sentry/types';
22

33
import type { InboundFiltersOptions } from '../../../src/integrations/inboundfilters';
44
import { InboundFilters } from '../../../src/integrations/inboundfilters';
5+
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
6+
7+
const PUBLIC_DSN = 'https://username@domain/123';
58

69
/**
710
* Creates an instance of the InboundFilters integration and returns
@@ -25,30 +28,22 @@ function createInboundFiltersEventProcessor(
2528
options: Partial<InboundFiltersOptions> = {},
2629
clientOptions: Partial<InboundFiltersOptions> = {},
2730
): EventProcessor {
28-
const eventProcessors: EventProcessor[] = [];
29-
const inboundFiltersInstance = new InboundFilters(options);
30-
31-
function addGlobalEventProcessor(processor: EventProcessor): void {
32-
eventProcessors.push(processor);
33-
expect(eventProcessors).toHaveLength(1);
34-
}
35-
36-
function getCurrentHub(): any {
37-
return {
38-
getIntegration(_integration: any): any {
39-
// pretend integration is enabled
40-
return inboundFiltersInstance;
41-
},
42-
getClient(): any {
43-
return {
44-
getOptions: () => clientOptions,
45-
};
46-
},
47-
};
48-
}
49-
50-
inboundFiltersInstance.setupOnce(addGlobalEventProcessor, getCurrentHub);
51-
return eventProcessors[0];
31+
const client = new TestClient(
32+
getDefaultTestClientOptions({
33+
dsn: PUBLIC_DSN,
34+
...clientOptions,
35+
defaultIntegrations: false,
36+
integrations: [new InboundFilters(options)],
37+
}),
38+
);
39+
40+
client.setupIntegrations();
41+
42+
const eventProcessors = client['_eventProcessors'];
43+
const eventProcessor = eventProcessors.find(processor => processor.id === 'InboundFilters');
44+
45+
expect(eventProcessor).toBeDefined();
46+
return eventProcessor!;
5247
}
5348

5449
// Fixtures

0 commit comments

Comments
 (0)