Skip to content

Commit d11db32

Browse files
authored
ref: Replace setup with preprocessEvent on Integration interface (#8969)
A change to #8956 based on feedback. I figured it makes sense to also pass the client (as in the one concrete example we have we actually need it 😅 ) - not sure if this should be the first or last argument, but IMHO you probably don't need this always and then it is nicer to have (event, hint) as the API...?
1 parent 72275c8 commit d11db32

File tree

4 files changed

+33
-40
lines changed

4 files changed

+33
-40
lines changed

packages/browser/src/integrations/linkederrors.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Integration } from '@sentry/types';
1+
import type { Client, Event, EventHint, Integration } from '@sentry/types';
22
import { applyAggregateErrorsToEvent } from '@sentry/utils';
33

44
import { exceptionFromError } from '../eventbuilder';
@@ -50,23 +50,17 @@ export class LinkedErrors implements Integration {
5050
/**
5151
* @inheritDoc
5252
*/
53-
public setup(client: Client): void {
54-
if (!client.on) {
55-
return;
56-
}
53+
public preprocessEvent(event: Event, hint: EventHint | undefined, client: Client): void {
54+
const options = client.getOptions();
5755

58-
client.on('preprocessEvent', (event, hint) => {
59-
const options = client.getOptions();
60-
61-
applyAggregateErrorsToEvent(
62-
exceptionFromError,
63-
options.stackParser,
64-
options.maxValueLength,
65-
this._key,
66-
this._limit,
67-
event,
68-
hint,
69-
);
70-
});
56+
applyAggregateErrorsToEvent(
57+
exceptionFromError,
58+
options.stackParser,
59+
options.maxValueLength,
60+
this._key,
61+
this._limit,
62+
event,
63+
hint,
64+
);
7165
}
7266
}

packages/core/src/integration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ export function setupIntegration(client: Client, integration: Integration, integ
106106
installedIntegrations.push(integration.name);
107107
}
108108

109-
integration.setup && integration.setup(client);
109+
if (client.on && typeof integration.preprocessEvent === 'function') {
110+
const callback = integration.preprocessEvent.bind(integration);
111+
client.on('preprocessEvent', (event, hint) => callback(event, hint, client));
112+
}
113+
110114
__DEBUG_BUILD__ && logger.log(`Integration installed: ${integration.name}`);
111115
}
112116

packages/node/src/integrations/linkederrors.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Integration } from '@sentry/types';
1+
import type { Client, Event, EventHint, Integration } from '@sentry/types';
22
import { applyAggregateErrorsToEvent } from '@sentry/utils';
33

44
import { exceptionFromError } from '../eventbuilder';
@@ -44,23 +44,17 @@ export class LinkedErrors implements Integration {
4444
/**
4545
* @inheritDoc
4646
*/
47-
public setup(client: Client): void {
48-
if (!client.on) {
49-
return;
50-
}
51-
52-
client.on('preprocessEvent', (event, hint) => {
53-
const options = client.getOptions();
54-
55-
applyAggregateErrorsToEvent(
56-
exceptionFromError,
57-
options.stackParser,
58-
options.maxValueLength,
59-
this._key,
60-
this._limit,
61-
event,
62-
hint,
63-
);
64-
});
47+
public preprocessEvent(event: Event, hint: EventHint | undefined, client: Client): void {
48+
const options = client.getOptions();
49+
50+
applyAggregateErrorsToEvent(
51+
exceptionFromError,
52+
options.stackParser,
53+
options.maxValueLength,
54+
this._key,
55+
this._limit,
56+
event,
57+
hint,
58+
);
6559
}
6660
}

packages/types/src/integration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Client } from './client';
2+
import type { Event, EventHint } from './event';
23
import type { EventProcessor } from './eventprocessor';
34
import type { Hub } from './hub';
45

@@ -26,7 +27,7 @@ export interface Integration {
2627
setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void;
2728

2829
/**
29-
* An optional hook that is called for each client, vs. only once.
30+
* An optional hook that allows to preprocess an event _before_ it is passed to all other event processors.
3031
*/
31-
setup?(client: Client): void;
32+
preprocessEvent?(event: Event, hint: EventHint | undefined, client: Client): void;
3233
}

0 commit comments

Comments
 (0)