Skip to content

Commit a12c405

Browse files
committed
refactor one integration as an example
1 parent a91624a commit a12c405

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Client, Event, EventHint, Integration, StackFrame } from '@sentry/
22
import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/utils';
33

44
import { DEBUG_BUILD } from '../debug-build';
5+
import { convertIntegrationFnToClass, makeIntegrationFn } from '../integration';
56

67
// "Script error." is hard coded into browsers for errors that it can't read.
78
// this is the result of a script being pulled in from an external domain and CORS.
@@ -28,42 +29,21 @@ export interface InboundFiltersOptions {
2829
disableTransactionDefaults: boolean;
2930
}
3031

31-
/** Inbound filters configurable by the user */
32-
export class InboundFilters implements Integration {
33-
/**
34-
* @inheritDoc
35-
*/
36-
public static id: string = 'InboundFilters';
37-
38-
/**
39-
* @inheritDoc
40-
*/
41-
public name: string;
42-
43-
private readonly _options: Partial<InboundFiltersOptions>;
44-
45-
public constructor(options: Partial<InboundFiltersOptions> = {}) {
46-
this.name = InboundFilters.id;
47-
this._options = options;
48-
}
49-
50-
/**
51-
* @inheritDoc
52-
*/
53-
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
54-
// noop
32+
const inboundFiltersIntegration = makeIntegrationFn('InboundFilters', (options: Partial<InboundFiltersOptions>) => {
33+
return {
34+
processEvent(event, _hint, client) {
35+
const clientOptions = client.getOptions();
36+
const mergedOptions = _mergeOptions(options, clientOptions);
37+
return _shouldDropEvent(event, mergedOptions) ? null : event;
38+
}
5539
}
40+
});
5641

57-
/** @inheritDoc */
58-
public processEvent(event: Event, _eventHint: EventHint, client: Client): Event | null {
59-
const clientOptions = client.getOptions();
60-
const options = _mergeOptions(this._options, clientOptions);
61-
return _shouldDropEvent(event, options) ? null : event;
62-
}
63-
}
42+
/** Inbound filters configurable by the user */
43+
// eslint-disable-next-line deprecation/deprecation
44+
export const InboundFilters = convertIntegrationFnToClass(inboundFiltersIntegration);
6445

65-
/** JSDoc */
66-
export function _mergeOptions(
46+
function _mergeOptions(
6747
internalOptions: Partial<InboundFiltersOptions> = {},
6848
clientOptions: Partial<InboundFiltersOptions> = {},
6949
): Partial<InboundFiltersOptions> {
@@ -84,8 +64,7 @@ export function _mergeOptions(
8464
};
8565
}
8666

87-
/** JSDoc */
88-
export function _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>): boolean {
67+
function _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>): boolean {
8968
if (options.ignoreInternal && _isSentryError(event)) {
9069
DEBUG_BUILD &&
9170
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);

0 commit comments

Comments
 (0)