Event Processors

You can enrich events with additional data by adding your own event processors, either on the scope level or globally. Though event processors are similar to beforeSend, there are two key differences:

  • beforeSend is guaranteed to be run last, after all other event processors, which means it gets the final version of the event right before it's sent (hence the name). Event processors added with either of the methods below run in an undetermined order, which means changes to the event may still be made after the event processor runs.
  • While beforeSend and processors added with Sentry.addGlobalEventProcessor run globally, regardless of scope, processors added with scope.addEventProcessor only run on events captured while that scope is active.

Both beforeSend and event processors are passed two arguments, the event itself and a hint object containing extra metadata.

Event processors added to the global scope will run on every event sent after they are added.

Copied
Sentry.configureScope(function(scope) {
  scope.addEventProcessor(function(event, hint) {
    // Add anything to the event here
    // returning `null` will drop the event
    return event;
  });
});

// You can do the same thing using `addGlobalEventProcessor`
Sentry.addGlobalEventProcessor(function(event, hint) {
  // Add anything to the event here
  // returning `null` will drop the event
  return event;
});

Event processors added to a local scope using withScope only apply to events captured inside that scope.

Copied
Sentry.withScope(function(scope) {
  scope.addEventProcessor(function(event, hint) {
    // Add anything to the event here
    // returning `null` will drop the event
    return event;
  });
  // The event processor will apply to this event
  Sentry.captureMessage("Test");
});

// The event processor will NOT apply to this event
Sentry.captureMessage("Test2");
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").