Skip to content

Commit abbc57f

Browse files
authored
feat(core): Add addEventProcessor method (#9554)
And deprecate `addGlobalEventProcessor()` and `getGlobalEventProcessors()`. In v8, all event processors will be on the client only, streamlining this a bit and preventing global "pollution". Closes #9082
1 parent 6a382a9 commit abbc57f

File tree

49 files changed

+134
-55
lines changed

Some content is hidden

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

49 files changed

+134
-55
lines changed

MIGRATION.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ npx @sentry/migr8@latest
88

99
This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes!
1010

11+
## Deprecate `addGlobalEventProcessor` in favor of `addEventProcessor`
12+
13+
Instead of using `addGlobalEventProcessor`, you should use `addEventProcessor` which does not add the event processor globally, but to the current client.
14+
15+
For the vast majority of cases, the behavior of these should be the same. Only in the case where you have multiple clients will this differ - but you'll likely want to add event processors per-client then anyhow, not globally.
16+
17+
In v8, we will remove the global event processors overall, as that allows us to avoid keeping global state that is not necessary.
18+
1119
## Deprecate `extractTraceParentData` export from `@sentry/core` & downstream packages
1220

1321
Instead, import this directly from `@sentry/utils`.

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/baseclient.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api';
4747
import { DEBUG_BUILD } from './debug-build';
4848
import { createEventEnvelope, createSessionEnvelope } from './envelope';
49+
import { getCurrentHub } from './hub';
4950
import type { IntegrationIndex } from './integration';
5051
import { setupIntegration, setupIntegrations } from './integration';
5152
import type { Scope } from './scope';
@@ -834,3 +835,17 @@ function isErrorEvent(event: Event): event is ErrorEvent {
834835
function isTransactionEvent(event: Event): event is TransactionEvent {
835836
return event.type === 'transaction';
836837
}
838+
839+
/**
840+
* Add an event processor to the current client.
841+
* This event processor will run for all events processed by this client.
842+
*/
843+
export function addEventProcessor(callback: EventProcessor): void {
844+
const client = getCurrentHub().getClient();
845+
846+
if (!client || !client.addEventProcessor) {
847+
return;
848+
}
849+
850+
client.addEventProcessor(callback);
851+
}

packages/core/src/eventProcessors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import { DEBUG_BUILD } from './debug-build';
55

66
/**
77
* Returns the global event processors.
8+
* @deprecated Global event processors will be removed in v8.
89
*/
910
export function getGlobalEventProcessors(): EventProcessor[] {
1011
return getGlobalSingleton<EventProcessor[]>('globalEventProcessors', () => []);
1112
}
1213

1314
/**
1415
* Add a EventProcessor to be kept globally.
15-
* @param callback EventProcessor to add
16+
* @deprecated Use `addEventProcessor` instead. Global event processors will be removed in v8.
1617
*/
1718
export function addGlobalEventProcessor(callback: EventProcessor): void {
19+
// eslint-disable-next-line deprecation/deprecation
1820
getGlobalEventProcessors().push(callback);
1921
}
2022

packages/core/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ 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+
} from './eventProcessors';
4548
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
46-
export { BaseClient } from './baseclient';
49+
export { BaseClient, addEventProcessor } from './baseclient';
4750
export { ServerRuntimeClient } from './server-runtime-client';
4851
export { initAndBind } from './sdk';
4952
export { createTransport } from './transports/base';

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

0 commit comments

Comments
 (0)