diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 37ea8bac06e9..9c6e8c9a546a 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -1,4 +1,4 @@ -import type { Event, EventProcessor, Hub, Integration, StackFrame } from '@sentry/types'; +import type { Client, Event, EventHint, Integration, StackFrame } from '@sentry/types'; import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/utils'; // "Script error." is hard coded into browsers for errors that it can't read. @@ -48,23 +48,15 @@ export class InboundFilters implements Integration { /** * @inheritDoc */ - public setupOnce(addGlobalEventProcessor: (processor: EventProcessor) => void, getCurrentHub: () => Hub): void { - const eventProcess: EventProcessor = (event: Event) => { - const hub = getCurrentHub(); - if (hub) { - const self = hub.getIntegration(InboundFilters); - if (self) { - const client = hub.getClient(); - const clientOptions = client ? client.getOptions() : {}; - const options = _mergeOptions(self._options, clientOptions); - return _shouldDropEvent(event, options) ? null : event; - } - } - return event; - }; + public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void { + // noop + } - eventProcess.id = this.name; - addGlobalEventProcessor(eventProcess); + /** @inheritDoc */ + public processEvent(event: Event, _eventHint: EventHint, client: Client): Event | null { + const clientOptions = client.getOptions(); + const options = _mergeOptions(this._options, clientOptions); + return _shouldDropEvent(event, options) ? null : event; } } diff --git a/packages/core/test/lib/integrations/inboundfilters.test.ts b/packages/core/test/lib/integrations/inboundfilters.test.ts index 9888a59eedff..8e42c5bc29ee 100644 --- a/packages/core/test/lib/integrations/inboundfilters.test.ts +++ b/packages/core/test/lib/integrations/inboundfilters.test.ts @@ -2,6 +2,9 @@ import type { Event, EventProcessor } from '@sentry/types'; import type { InboundFiltersOptions } from '../../../src/integrations/inboundfilters'; import { InboundFilters } from '../../../src/integrations/inboundfilters'; +import { getDefaultTestClientOptions, TestClient } from '../../mocks/client'; + +const PUBLIC_DSN = 'https://username@domain/123'; /** * Creates an instance of the InboundFilters integration and returns @@ -25,30 +28,22 @@ function createInboundFiltersEventProcessor( options: Partial = {}, clientOptions: Partial = {}, ): EventProcessor { - const eventProcessors: EventProcessor[] = []; - const inboundFiltersInstance = new InboundFilters(options); - - function addGlobalEventProcessor(processor: EventProcessor): void { - eventProcessors.push(processor); - expect(eventProcessors).toHaveLength(1); - } - - function getCurrentHub(): any { - return { - getIntegration(_integration: any): any { - // pretend integration is enabled - return inboundFiltersInstance; - }, - getClient(): any { - return { - getOptions: () => clientOptions, - }; - }, - }; - } - - inboundFiltersInstance.setupOnce(addGlobalEventProcessor, getCurrentHub); - return eventProcessors[0]; + const client = new TestClient( + getDefaultTestClientOptions({ + dsn: PUBLIC_DSN, + ...clientOptions, + defaultIntegrations: false, + integrations: [new InboundFilters(options)], + }), + ); + + client.setupIntegrations(); + + const eventProcessors = client['_eventProcessors']; + const eventProcessor = eventProcessors.find(processor => processor.id === 'InboundFilters'); + + expect(eventProcessor).toBeDefined(); + return eventProcessor!; } // Fixtures