Event Processors
Learn more about how you can add your own event processors globally or to the current scope.
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:
- Event processors added with either
add_global_event_processor
orscope.add_event_processor
run in an undetermined order, which means changes to the event may still be made after the event processor runs.before_send
andbefore_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). - While
before_send
,before_send_transaction
, and processors added withadd_global_event_processor
run globally, regardless of scope, processors added withscope.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 containing extra metadata.
Event processors added to the global scope will run on every event sent after they've been added.
Copied
import sentry_sdk
from sentry_sdk.types import Event, Hint
from sentry_sdk.scope import add_global_event_processor
sentry_sdk.init(
# ...
)
def event_processor(event, hint):
event["tags"] = {"foo": "42"}
return event
global_scope = sentry_sdk.get_global_scope()
global_scope.add_event_processor(event_processor)
# You can do the same thing using add_global_event_processor
add_global_event_processor(event_processor)
Event processors added to a local scope using new_scope
or isolation_scope
will only apply to events captured inside that scope.
Copied
with sentry_sdk.new_scope() as scope:
scope.add_event_processor(event_processor)
# The processor applies only inside this scope
sentry_sdk.capture_message("Test")
# The event processor will NOT apply to this event
sentry_sdk.capture_message("Test");
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").