Skip to content

fix(core): Run client eventProcessors before global ones #9032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,11 @@ export class Scope implements ScopeInterface {
* @param hint Object containing additional information about the original exception, for use by the event processors.
* @hidden
*/
public applyToEvent(event: Event, hint: EventHint = {}): PromiseLike<Event | null> {
public applyToEvent(
event: Event,
hint: EventHint = {},
additionalEventProcessors?: EventProcessor[],
): PromiseLike<Event | null> {
if (this._extra && Object.keys(this._extra).length) {
event.extra = { ...this._extra, ...event.extra };
}
Expand Down Expand Up @@ -517,7 +521,12 @@ export class Scope implements ScopeInterface {
propagationContext: this._propagationContext,
};

return notifyEventProcessors([...getGlobalEventProcessors(), ...this._eventProcessors], event, hint);
// TODO (v8): Update this order to be: Global > Client > Scope
return notifyEventProcessors(
[...(additionalEventProcessors || []), ...getGlobalEventProcessors(), ...this._eventProcessors],
event,
hint,
);
}

/**
Expand Down
40 changes: 19 additions & 21 deletions packages/core/src/utils/prepareEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function prepareEvent(
// We prepare the result here with a resolved Event.
let result = resolvedSyncPromise<Event | null>(prepared);

const clientEventProcessors = client && client.getEventProcessors ? client.getEventProcessors() : [];

// This should be the last thing called, since we want that
// {@link Hub.addEventProcessor} gets the finished prepared event.
//
Expand All @@ -73,31 +75,27 @@ export function prepareEvent(
}

// In case we have a hub we reassign it.
result = finalScope.applyToEvent(prepared, hint);
result = finalScope.applyToEvent(prepared, hint, clientEventProcessors);
} else {
// Apply global event processors even if there is no scope
result = notifyEventProcessors(getGlobalEventProcessors(), prepared, hint);
// Apply client & global event processors even if there is no scope
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in some tests we actually ran into this branch, so IMHO it makes sense to ensure also global processors run if no scope is supplied (which is also kind of weird right now). This should only really be a problem when not going through getCurrentHub().xxx, as there we always put the scope, but e.g. if you call captureException() on the client directly or similar, this is not guaranteed to be there.

// TODO (v8): Update the order to be Global > Client
result = notifyEventProcessors([...clientEventProcessors, ...getGlobalEventProcessors()], prepared, hint);
}

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

if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
return normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
}
return evt;
});
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
return normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
}
return evt;
});
}

/**
Expand Down