Skip to content

Commit e0d1131

Browse files
committed
feat(core): Add addEventProcessor method
And deprecate `addGlobalEventProcessor()` and `getGlobalEventProcessors()`. In v8, all event processors will be on the client only, streamlining this a bit and preventing global "pollution".
1 parent f8cebde commit e0d1131

File tree

47 files changed

+127
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+127
-54
lines changed

packages/astro/src/index.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { handleRequest } from './server/middleware';
88

99
// Hence, we export everything from the Node SDK explicitly:
1010
export {
11+
// eslint-disable-next-line deprecation/deprecation
1112
addGlobalEventProcessor,
13+
addEventProcessor,
1214
addBreadcrumb,
1315
captureException,
1416
captureEvent,

packages/browser/src/exports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export type { BrowserOptions } from './client';
2121
export type { ReportDialogOptions } from './helpers';
2222

2323
export {
24+
// eslint-disable-next-line deprecation/deprecation
2425
addGlobalEventProcessor,
26+
addEventProcessor,
2527
addBreadcrumb,
2628
addIntegration,
2729
captureException,

packages/browser/src/integrations/dedupe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Dedupe implements Integration {
2525
}
2626

2727
/** @inheritDoc */
28-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
28+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
2929
// noop
3030
}
3131

packages/bun/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export type { TransactionNamingScheme } from '@sentry/node';
2424
export type { BunOptions } from './types';
2525

2626
export {
27+
// eslint-disable-next-line deprecation/deprecation
2728
addGlobalEventProcessor,
29+
addEventProcessor,
2830
addBreadcrumb,
2931
addIntegration,
3032
captureException,

packages/core/src/eventProcessors.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@ import { SyncPromise, getGlobalSingleton, isThenable, logger } from '@sentry/uti
33

44
import { DEBUG_BUILD } from './debug-build';
55

6+
import { getCurrentHub } from './hub';
7+
68
/**
79
* Returns the global event processors.
10+
* @deprecated Global event processors will be removed in v8.
811
*/
912
export function getGlobalEventProcessors(): EventProcessor[] {
1013
return getGlobalSingleton<EventProcessor[]>('globalEventProcessors', () => []);
1114
}
1215

1316
/**
1417
* Add a EventProcessor to be kept globally.
15-
* @param callback EventProcessor to add
18+
* @deprecated Use `addEventProcessor` instead. Global event processors will be removed in v8.
1619
*/
1720
export function addGlobalEventProcessor(callback: EventProcessor): void {
21+
// eslint-disable-next-line deprecation/deprecation
1822
getGlobalEventProcessors().push(callback);
1923
}
2024

25+
/**
26+
* Add an event processor to the current client.
27+
* This event processor will run for all events processed by this client.
28+
*/
29+
export function addEventProcessor(callback: EventProcessor): void {
30+
const client = getCurrentHub().getClient();
31+
32+
if (!client || !client.addEventProcessor) {
33+
return;
34+
}
35+
36+
client.addEventProcessor(callback);
37+
}
38+
2139
/**
2240
* Process an array of event processors, returning the processed event (or `null` if the event was dropped).
2341
*/

packages/core/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export {
4141
export { makeSession, closeSession, updateSession } from './session';
4242
export { SessionFlusher } from './sessionflusher';
4343
export { Scope } from './scope';
44-
export { addGlobalEventProcessor } from './eventProcessors';
44+
export {
45+
// eslint-disable-next-line deprecation/deprecation
46+
addGlobalEventProcessor,
47+
addEventProcessor,
48+
} from './eventProcessors';
4549
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
4650
export { BaseClient } from './baseclient';
4751
export { ServerRuntimeClient } from './server-runtime-client';

packages/core/src/integration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
105105

106106
// `setupOnce` is only called the first time
107107
if (installedIntegrations.indexOf(integration.name) === -1) {
108+
// eslint-disable-next-line deprecation/deprecation
108109
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
109110
installedIntegrations.push(integration.name);
110111
}

packages/core/src/integrations/inboundfilters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class InboundFilters implements Integration {
5050
/**
5151
* @inheritDoc
5252
*/
53-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
53+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
5454
// noop
5555
}
5656

packages/core/src/scope.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,12 @@ export class Scope implements ScopeInterface {
523523

524524
// TODO (v8): Update this order to be: Global > Client > Scope
525525
return notifyEventProcessors(
526-
[...(additionalEventProcessors || []), ...getGlobalEventProcessors(), ...this._eventProcessors],
526+
[
527+
...(additionalEventProcessors || []),
528+
// eslint-disable-next-line deprecation/deprecation
529+
...getGlobalEventProcessors(),
530+
...this._eventProcessors,
531+
],
527532
event,
528533
hint,
529534
);

packages/core/src/utils/prepareEvent.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ export function prepareEvent(
110110
} else {
111111
// Apply client & global event processors even if there is no scope
112112
// TODO (v8): Update the order to be Global > Client
113-
result = notifyEventProcessors([...clientEventProcessors, ...getGlobalEventProcessors()], prepared, hint);
113+
result = notifyEventProcessors(
114+
[
115+
...clientEventProcessors,
116+
// eslint-disable-next-line deprecation/deprecation
117+
...getGlobalEventProcessors(),
118+
],
119+
prepared,
120+
hint,
121+
);
114122
}
115123

116124
return result.then(evt => {

0 commit comments

Comments
 (0)