sentry-electron icon indicating copy to clipboard operation
sentry-electron copied to clipboard

Make `beforeSend` work from renderers

Open timfish opened this issue 3 years ago • 5 comments

Renderer events are passed to the main process via the EventToMain integration. The downside of using an integration/global event processor to do this is that the renderer beforeSend never gets called.

This PR calls beforeSend from EventToMain so that it functions as it should!

This closes #533.

timfish avatar Aug 15 '22 23:08 timfish

🤔 just realised this doesn't take into account any modifications to hint which is required to add attachments from beforeSend...

timfish avatar Aug 16 '22 00:08 timfish

This now passes [event, hint] serialised from render to main and adds a test that ensures that hint.attachments added in the renderer beforeSend are submitted in envelopes from the main.

My understanding is this will currently only work with string attachments since UInt8Array get's mangled by json stringify.

timfish avatar Aug 16 '22 01:08 timfish

beforeSend explicitly is meant to run after the event processors - https://develop.sentry.dev/sdk/unified-api/#event-pipeline, not sure if we can make this change.

AbhiPrasad avatar Aug 16 '22 15:08 AbhiPrasad

beforeSend explicitly is meant to run after the event processors

If EventToMain is the last integration, will this not be true?

timfish avatar Aug 16 '22 15:08 timfish

not sure if we can make this change.

Currently, beforeSend is not called at all in the renderer process so it's currently not possible to do anything before an event is passed to the main process.

Alternatives

  • Pass an optional beforeSend callback to the EventToMain integration
    • I don't really like this because it needs documenting and differs from the SDK norms
  • Stop using EventToMain integration and instead use a custom transport to pass to the main process
    • This has a few downsides including:
      • We would need to parse the envelope from the renderer in the main process!
      • It would almost certainly be a semver breaking change unless we somehow kept both routes working until v5

timfish avatar Aug 22 '22 15:08 timfish

#610 means this will no longer be required

timfish avatar Dec 29 '22 14:12 timfish