Skip to content

Commit 74aedfa

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 13b4b47 commit 74aedfa

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
@@ -7,7 +7,9 @@ import { sentryAstro } from './integration';
77

88
// Hence, we export everything from the Node SDK explicitly:
99
export {
10+
// eslint-disable-next-line deprecation/deprecation
1011
addGlobalEventProcessor,
12+
addEventProcessor,
1113
addBreadcrumb,
1214
captureException,
1315
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
@@ -23,7 +23,7 @@ export class Dedupe implements Integration {
2323
}
2424

2525
/** @inheritDoc */
26-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
26+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
2727
// noop
2828
}
2929

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
@@ -1,21 +1,39 @@
11
import type { Event, EventHint, EventProcessor } from '@sentry/types';
22
import { getGlobalSingleton, isThenable, logger, SyncPromise } from '@sentry/utils';
33

4+
import { getCurrentHub } from './hub';
5+
46
/**
57
* Returns the global event processors.
8+
* @deprecated Global event processors will be removed in v8.
69
*/
710
export function getGlobalEventProcessors(): EventProcessor[] {
811
return getGlobalSingleton<EventProcessor[]>('globalEventProcessors', () => []);
912
}
1013

1114
/**
1215
* Add a EventProcessor to be kept globally.
13-
* @param callback EventProcessor to add
16+
* @deprecated Use `addEventProcessor` instead. Global event processors will be removed in v8.
1417
*/
1518
export function addGlobalEventProcessor(callback: EventProcessor): void {
19+
// eslint-disable-next-line deprecation/deprecation
1620
getGlobalEventProcessors().push(callback);
1721
}
1822

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

packages/core/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export {
3939
export { makeSession, closeSession, updateSession } from './session';
4040
export { SessionFlusher } from './sessionflusher';
4141
export { Scope } from './scope';
42-
export { addGlobalEventProcessor } from './eventProcessors';
42+
export {
43+
// eslint-disable-next-line deprecation/deprecation
44+
addGlobalEventProcessor,
45+
addEventProcessor,
46+
} from './eventProcessors';
4347
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
4448
export { BaseClient } from './baseclient';
4549
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
@@ -103,6 +103,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
103103

104104
// `setupOnce` is only called the first time
105105
if (installedIntegrations.indexOf(integration.name) === -1) {
106+
// eslint-disable-next-line deprecation/deprecation
106107
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
107108
installedIntegrations.push(integration.name);
108109
}

packages/core/src/integrations/inboundfilters.ts

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

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
@@ -79,7 +79,15 @@ export function prepareEvent(
7979
} else {
8080
// Apply client & global event processors even if there is no scope
8181
// TODO (v8): Update the order to be Global > Client
82-
result = notifyEventProcessors([...clientEventProcessors, ...getGlobalEventProcessors()], prepared, hint);
82+
result = notifyEventProcessors(
83+
[
84+
...clientEventProcessors,
85+
// eslint-disable-next-line deprecation/deprecation
86+
...getGlobalEventProcessors(),
87+
],
88+
prepared,
89+
hint,
90+
);
8391
}
8492

8593
return result.then(evt => {

0 commit comments

Comments
 (0)