Sentry-javascript: Missing Sentry.setDataCallback

Created on 19 Sep 2018  路  8Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [x] @sentry/browser
  • [ ] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [ ] other:

Version:

4.0.2

Description

The previous version raven-js had the ability to add setDataCallback which was executed before data was sent out. Current version @sentry/browser enables beforeSend but it can be only set as part of the init process.

Could you please add an ability to set beforeSend callback also in a later stage? I am trying to fix my redux integration previously done using https://github.com/captbaritone/raven-for-redux/blob/master/index.js

Most helpful comment

Hey, you should be able to use an event processor.

So in any point in time you can do:

Sentry.configureScope(scope => {
  scope.addEventProcessor(async event => {
    // Add anything to the event here
    // returning null will not send the event
    return event;
  });
});

Hope this helps.

All 8 comments

Hey, you should be able to use an event processor.

So in any point in time you can do:

Sentry.configureScope(scope => {
  scope.addEventProcessor(async event => {
    // Add anything to the event here
    // returning null will not send the event
    return event;
  });
});

Hope this helps.

Works beautifully! Thanks :)

You could also add this in the docs...

Beautiful! Thanks :)

Hi.

I've tried using the scope.addEventProcessor method to add extra data to the scope. It was going well until I noticed that this method gets called when sentry is about to send the error and not when the error is thrown. Since I'm using Redux, I'm getting misleading information as there are breadcrumbs which happened after the exception.

Any ideas on how to deal with this?

For reference, I got it working by storing the state when the lastEventId is changed (which means an error was thrown) and then using this stored data to modify the scope using addEventProcessor.

You can check out this gist: https://gist.github.com/olavoasantos/9ac791098758ee7dedf0c0424ec8b398

It looks like the section on event processors was removed from the documentation. Is this still the recommended way to look up and attach additional metadata when Sentry is about to send an exception? Or do we use beforeSend now?

@cyounkins both are correct, but beforeSend can be set just once during initialization, where eventProcessors can be added anytime and they can also work for only specific events (scope) if desired. https://docs.sentry.io/platforms/node/#eventprocessors
(JS docs are being reworked now, thus some parts may be missing, sorry about that)

Was this page helpful?
0 / 5 - 0 ratings