Skip to content

Commit 42ddf41

Browse files
authored
fix(core): Run client eventProcessors before global ones (#9032)
I noticed that while from an API POV the current behavior makes kind-of sense IMHO: 1. Run global event processors 2. Run scope event processors 3. Run client event processors It is potentially breaking, as if we rewrite integrations to use the new client processors, their processing will run after any user global event processors, leading to potentially unexpected outcomes. So this PR changes this to instead run them in this order: 1. Run client event processors 2. Run global event processors 3. Run scope event processors Which should be more stable for now. In v8, we should update this to run a more sensible order: 1. Global 2. Client 3. Scope
1 parent 4583f80 commit 42ddf41

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

packages/core/src/scope.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ export class Scope implements ScopeInterface {
467467
* @param hint Object containing additional information about the original exception, for use by the event processors.
468468
* @hidden
469469
*/
470-
public applyToEvent(event: Event, hint: EventHint = {}): PromiseLike<Event | null> {
470+
public applyToEvent(
471+
event: Event,
472+
hint: EventHint = {},
473+
additionalEventProcessors?: EventProcessor[],
474+
): PromiseLike<Event | null> {
471475
if (this._extra && Object.keys(this._extra).length) {
472476
event.extra = { ...this._extra, ...event.extra };
473477
}
@@ -517,7 +521,12 @@ export class Scope implements ScopeInterface {
517521
propagationContext: this._propagationContext,
518522
};
519523

520-
return notifyEventProcessors([...getGlobalEventProcessors(), ...this._eventProcessors], event, hint);
524+
// TODO (v8): Update this order to be: Global > Client > Scope
525+
return notifyEventProcessors(
526+
[...(additionalEventProcessors || []), ...getGlobalEventProcessors(), ...this._eventProcessors],
527+
event,
528+
hint,
529+
);
521530
}
522531

523532
/**

packages/core/src/utils/prepareEvent.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function prepareEvent(
5555
// We prepare the result here with a resolved Event.
5656
let result = resolvedSyncPromise<Event | null>(prepared);
5757

58+
const clientEventProcessors = client && client.getEventProcessors ? client.getEventProcessors() : [];
59+
5860
// This should be the last thing called, since we want that
5961
// {@link Hub.addEventProcessor} gets the finished prepared event.
6062
//
@@ -73,31 +75,27 @@ export function prepareEvent(
7375
}
7476

7577
// In case we have a hub we reassign it.
76-
result = finalScope.applyToEvent(prepared, hint);
78+
result = finalScope.applyToEvent(prepared, hint, clientEventProcessors);
7779
} else {
78-
// Apply global event processors even if there is no scope
79-
result = notifyEventProcessors(getGlobalEventProcessors(), prepared, hint);
80+
// Apply client & global event processors even if there is no scope
81+
// TODO (v8): Update the order to be Global > Client
82+
result = notifyEventProcessors([...clientEventProcessors, ...getGlobalEventProcessors()], prepared, hint);
8083
}
8184

82-
return result
83-
.then(evt => {
84-
// Process client-scoped event processors
85-
return client && client.getEventProcessors ? notifyEventProcessors(client.getEventProcessors(), evt, hint) : evt;
86-
})
87-
.then(evt => {
88-
if (evt) {
89-
// We apply the debug_meta field only after all event processors have ran, so that if any event processors modified
90-
// file names (e.g.the RewriteFrames integration) the filename -> debug ID relationship isn't destroyed.
91-
// This should not cause any PII issues, since we're only moving data that is already on the event and not adding
92-
// any new data
93-
applyDebugMeta(evt);
94-
}
85+
return result.then(evt => {
86+
if (evt) {
87+
// We apply the debug_meta field only after all event processors have ran, so that if any event processors modified
88+
// file names (e.g.the RewriteFrames integration) the filename -> debug ID relationship isn't destroyed.
89+
// This should not cause any PII issues, since we're only moving data that is already on the event and not adding
90+
// any new data
91+
applyDebugMeta(evt);
92+
}
9593

96-
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
97-
return normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
98-
}
99-
return evt;
100-
});
94+
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
95+
return normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
96+
}
97+
return evt;
98+
});
10199
}
102100

103101
/**

0 commit comments

Comments
 (0)