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 => {

packages/deno/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export type { AddRequestDataToEventOptions } from '@sentry/utils';
2323
export type { DenoOptions } from './types';
2424

2525
export {
26+
// eslint-disable-next-line deprecation/deprecation
2627
addGlobalEventProcessor,
28+
addEventProcessor,
2729
addBreadcrumb,
2830
captureException,
2931
captureEvent,

packages/e2e-tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ A standardized frontend test application has the following features:
107107
be done with an event processor:
108108

109109
```ts
110-
Sentry.addGlobalEventProcessor(event => {
110+
Sentry.addEventProcessor(event => {
111111
if (
112112
event.type === 'transaction' &&
113113
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/create-next-app/sentry.client.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Sentry.init({
1616
// that it will also get attached to your source maps
1717
});
1818

19-
Sentry.addGlobalEventProcessor(event => {
19+
Sentry.addEventProcessor(event => {
2020
if (
2121
event.type === 'transaction' &&
2222
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/create-next-app/sentry.server.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Sentry.init({
2323
integrations: [new Sentry.Integrations.LocalVariables()],
2424
});
2525

26-
Sentry.addGlobalEventProcessor(event => {
26+
Sentry.addEventProcessor(event => {
2727
global.transactionIds = global.transactionIds || [];
2828

2929
if (event.type === 'transaction') {

packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Sentry.init({
2424
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
2525
});
2626

27-
Sentry.addGlobalEventProcessor(event => {
27+
Sentry.addEventProcessor(event => {
2828
if (
2929
event.type === 'transaction' &&
3030
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/create-remix-app/app/entry.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Sentry.init({
2424
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
2525
});
2626

27-
Sentry.addGlobalEventProcessor(event => {
27+
Sentry.addEventProcessor(event => {
2828
if (
2929
event.type === 'transaction' &&
3030
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/node-express-app/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ app.listen(port, () => {
8989
console.log(`Example app listening on port ${port}`);
9090
});
9191

92-
Sentry.addGlobalEventProcessor(event => {
92+
Sentry.addEventProcessor(event => {
9393
global.transactionIds = global.transactionIds || [];
9494

9595
if (event.type === 'transaction') {

packages/e2e-tests/test-applications/react-create-hash-router/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Object.defineProperty(window, 'sentryReplayId', {
4747
},
4848
});
4949

50-
Sentry.addGlobalEventProcessor(event => {
50+
Sentry.addEventProcessor(event => {
5151
if (
5252
event.type === 'transaction' &&
5353
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/react-router-6-use-routes/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Object.defineProperty(window, 'sentryReplayId', {
4545
},
4646
});
4747

48-
Sentry.addGlobalEventProcessor(event => {
48+
Sentry.addEventProcessor(event => {
4949
if (
5050
event.type === 'transaction' &&
5151
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/standard-frontend-react-tracing-import/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Sentry.init({
3434
release: 'e2e-test',
3535
});
3636

37-
Sentry.addGlobalEventProcessor(event => {
37+
Sentry.addEventProcessor(event => {
3838
if (
3939
event.type === 'transaction' &&
4040
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/e2e-tests/test-applications/standard-frontend-react/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Object.defineProperty(window, 'sentryReplayId', {
4646
},
4747
});
4848

49-
Sentry.addGlobalEventProcessor(event => {
49+
Sentry.addEventProcessor(event => {
5050
if (
5151
event.type === 'transaction' &&
5252
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')

packages/ember/tests/test-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare global {
1313
}
1414
}
1515

16-
Sentry.addGlobalEventProcessor(event => {
16+
Sentry.addEventProcessor(event => {
1717
if (isTesting()) {
1818
if (!window._sentryTestEvents) {
1919
window._sentryTestEvents = [];

packages/hub/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export const getCurrentHub = getCurrentHubCore;
4646
/**
4747
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
4848
*/
49-
export const addGlobalEventProcessor = addGlobalEventProcessorCore;
49+
50+
export const addGlobalEventProcessor = addGlobalEventProcessorCore; // eslint-disable-line deprecation/deprecation
5051

5152
/**
5253
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.

packages/hub/test/scope.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ describe('Scope', () => {
644644
const localScope = new Scope();
645645
localScope.setExtra('a', 'b');
646646

647+
// eslint-disable-next-line deprecation/deprecation
647648
addGlobalEventProcessor((processedEvent: Event) => {
648649
processedEvent.dist = '1';
649650
return processedEvent;

packages/integrations/src/contextlines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class ContextLines implements Integration {
4444
/**
4545
* @inheritDoc
4646
*/
47-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
47+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
4848
// noop
4949
}
5050

packages/integrations/src/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/integrations/src/extraerrordata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ExtraErrorData implements Integration {
3838
/**
3939
* @inheritDoc
4040
*/
41-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
41+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
4242
// noop
4343
}
4444

packages/integrations/src/rewriteframes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class RewriteFrames implements Integration {
4343
/**
4444
* @inheritDoc
4545
*/
46-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
46+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
4747
// noop
4848
}
4949

packages/integrations/src/sessiontiming.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class SessionTiming implements Integration {
2323
/**
2424
* @inheritDoc
2525
*/
26-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
26+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
2727
// noop
2828
}
2929

packages/integrations/src/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Transaction implements Integration {
1919
/**
2020
* @inheritDoc
2121
*/
22-
public setupOnce(_addGlobaleventProcessor: unknown, _getCurrentHub: unknown): void {
22+
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
2323
// noop
2424
}
2525

packages/node-experimental/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export {
2424
extractRequestData,
2525
deepReadDirSync,
2626
getModuleFromFilename,
27+
// eslint-disable-next-line deprecation/deprecation
2728
addGlobalEventProcessor,
29+
addEventProcessor,
2830
addBreadcrumb,
2931
captureException,
3032
captureEvent,

packages/node/src/anr/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getClient, makeSession, updateSession } from '@sentry/core';
33
import type { Event, Session, StackFrame } from '@sentry/types';
44
import { logger, watchdogTimer } from '@sentry/utils';
55

6-
import { addGlobalEventProcessor, captureEvent, flush, getCurrentHub } from '..';
6+
import { addEventProcessor, captureEvent, flush, getCurrentHub } from '..';
77
import { captureStackTrace } from './debugger';
88

99
const DEFAULT_INTERVAL = 50;
@@ -191,7 +191,7 @@ function handleChildProcess(options: Options): void {
191191
});
192192
}
193193

194-
addGlobalEventProcessor(event => {
194+
addEventProcessor(event => {
195195
// Strip sdkProcessingMetadata from all child process events to remove trace info
196196
delete event.sdkProcessingMetadata;
197197
event.tags = {

packages/node/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export type { AddRequestDataToEventOptions, TransactionNamingScheme } from '@sen
2323
export type { NodeOptions } from './types';
2424

2525
export {
26+
// eslint-disable-next-line deprecation/deprecation
2627
addGlobalEventProcessor,
28+
addEventProcessor,
2729
addBreadcrumb,
2830
addIntegration,
2931
captureException,

packages/opentelemetry-node/src/spanprocessor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Context } from '@opentelemetry/api';
22
import { SpanKind, context, trace } from '@opentelemetry/api';
33
import { suppressTracing } from '@opentelemetry/core';
44
import type { Span as OtelSpan, SpanProcessor as OtelSpanProcessor } from '@opentelemetry/sdk-trace-base';
5-
import { Transaction, addGlobalEventProcessor, addTracingExtensions, getClient, getCurrentHub } from '@sentry/core';
5+
import { addEventProcessor, addTracingExtensions, getClient, getCurrentHub, Transaction } from '@sentry/core';
66
import type { DynamicSamplingContext, Span as SentrySpan, TraceparentData, TransactionContext } from '@sentry/types';
77
import { logger } from '@sentry/utils';
88

@@ -22,7 +22,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
2222
public constructor() {
2323
addTracingExtensions();
2424

25-
addGlobalEventProcessor(event => {
25+
addEventProcessor(event => {
2626
const otelSpan = trace && trace.getActiveSpan && (trace.getActiveSpan() as OtelSpan | undefined);
2727
if (!otelSpan) {
2828
return event;

0 commit comments

Comments
 (0)