---
title: "Event Processors"
description: "Learn more about how you can add your own event processors globally or to the current scope."
url: https://docs.sentry.io/platforms/ruby/guides/rack/enriching-events/event-processors/
---

# Event Processors | Sentry for Rack Middleware

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 `before_send` and `before_send_transaction`, there are two key differences:

* `before_send` and `before_send_transaction` are guaranteed to be run last, after all other event processors, (which means they get 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 `before_send`, `before_send_transaction`, and processors added with `Sentry.add_global_event_processor` run globally, regardless of scope, processors added with `scope.add_event_processor` only run on events captured while that scope is active.

Like `before_send` and `before_send_transaction`, event processors are passed two arguments, the event itself and [a `hint` object](https://docs.sentry.io/platforms/ruby/guides/rack/configuration/filtering.md#using-hints) containing extra metadata.

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

```ruby
Sentry.init do |config|
  # ...
end

Sentry.configure_scope do |scope|
  scope.add_event_processor do |event, hint|
     # can mutate the event here
     # returning nil will drop the event
     event.tags = { foo: 42 }
     event
  end
end

# You can do the same thing using add_global_event_processor
Sentry.add_global_event_processor do |event, hint|
  event.tags = { foo: 42 }
  event
end
```

Event processors added to a local scope using `with_scope` will only apply to events captured inside that scope.

```ruby
Sentry.with_scope do |scope|
  scope.add_event_processor do |event, hint|
     # can mutate the event here
     # returning nil will drop the event
     event.tags = { foo: 42 }
     event
  end

  # The event processor will apply to this event
  Sentry.captureMessage("Test");
end

# The event processor will NOT apply to this event
Sentry.captureMessage("Test2");
```
