Skip to content
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

feat(core): Introduce processEvent hook on Integration #9017

Merged
merged 3 commits into from
Sep 15, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Sep 13, 2023

This adds a new (optional) processEvent hook on the Integration interface, which allows to register an event processor for the current client only.

This has actually correct semantics in that the processor will only be registered for the client that the integration is added for. This is done by adding a new addEventProcessor method on the client, which for now are called after all global & scope event processors.

Previously, all integrations always registered a global event processor, which is not really necessary. With this, we can be much more focused & also skip checking for existence of the integration on the client etc.

Supersedes #9015

@github-actions
Copy link
Contributor

github-actions bot commented Sep 13, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.52 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.39 KB (+0.22% 🔺)
@sentry/browser - Webpack (gzipped) 21.99 KB (+0.33% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 70.25 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.59 KB (+0.31% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.66 KB (+0.31% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 222.09 KB (+0.14% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 86.63 KB (+0.35% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 61.48 KB (+0.5% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.46 KB (+0.25% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.54 KB (+0.17% 🔺)
@sentry/react - Webpack (gzipped) 22.02 KB (+0.32% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.43 KB (+0.17% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 51.02 KB (+0.27% 🔺)

* An optional hook that allows to process an event.
* Return `null` to drop the event, or mutate the event & return it.
*/
processEvent?(event: Event, hint: EventHint | undefined, client: Client): Event | null | PromiseLike<Event | null>;
Copy link
Member

Choose a reason for hiding this comment

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

giga nit: Can we add JS doc explaining that the client arg here is the client that recorded the event?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, true, didn't actually update the comment here yet, will do!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Can we add some tests around registering the processEvent hooks? (Feel free to disgregard if this is done anyway in follow-up PRs).

@mydea mydea force-pushed the fn/integration-processEvent branch from c2d603d to c354494 Compare September 14, 2023 14:42
@mydea
Copy link
Member Author

mydea commented Sep 14, 2023

I added tests for the new integration API, and actually also for setupOnce & preprocessEvent, to really make the expected/current behavior clear!

return result
.then(evt => {
// Process client-scoped event processors
return client && client.getEventProcessors ? notifyEventProcessors(client.getEventProcessors(), evt, hint) : evt;
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 actually noticed a problem with the implementation in one of the other PRs (for browser). Which is that we can't just call this after prepareEvent is completed in the baseclient, because then the stuff that happens in here below will not be applied correctly.

So I updated it to instead run this here. And I am wondering, what do you think is nicer:

  1. Expose getEventProcessors() on the client (like I did here)
  2. Instead expose e.g. applyToEvent() like we have on the scope and call that directly (which under the hood applies the event processors)?

cc @AbhiPrasad / @Lms24 / @lforst

Copy link
Member

Choose a reason for hiding this comment

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

Let's do getEventProcessors on the client - I'd rather not show more internals than what is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good. we maybe will adjust this for v8 anyhow if we adjust the event processing pipeline, but should be good for now I guess.

@mydea mydea merged commit 2356e80 into develop Sep 15, 2023
@mydea mydea deleted the fn/integration-processEvent branch September 15, 2023 08:07
billyvg pushed a commit that referenced this pull request Sep 15, 2023
This adds a new (optional) `processEvent` hook on the `Integration`
interface, which allows to register an event processor **for the current
client only**.

This has actually correct semantics in that the processor will only be
registered for the client that the integration is added for. This is
done by adding a new `addEventProcessor` method on the client, which for
now are called after all global & scope event processors.

Previously, all integrations always registered a _global_ event
processor, which is not really necessary. With this, we can be much more
focused & also skip checking for existence of the integration on the
client etc.
@timfish
Copy link
Collaborator

timfish commented Oct 2, 2023

The hint: EventHint | undefined parameter in this new hook means that it cannot be used to add attachments.

All the other event processor functions don't allow undefined here and pass an empty object so you can add attachments to events like this:

hint.attachments = hint.attachments || [];
hint.attachments.push({...});

@mydea
Copy link
Member Author

mydea commented Oct 2, 2023

The hint: EventHint | undefined parameter in this new hook means that it cannot be used to add attachments.

All the other event processor functions don't allow undefined here and pass an empty object so you can add attachments to events like this:

hint.attachments = hint.attachments || [];
hint.attachments.push({...});

Hmm, good catch! We can update this in a backwards compatible way (just update the method signature), I think I just copied this from preprocessEvent but this works differently. I'll do this!

@mydea
Copy link
Member Author

mydea commented Oct 2, 2023

See: #9151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants