Event context
You can add custom metadata to the events sent to Honeybadger Insights by using
the honeybadger.set_event_context function. This metadata will be included in
each event call within the current thread.
from honeybadger import honeybadger
honeybadger.set_event_context( user_id=user.id, session_id=session.id)Context lifecycle
Section titled “Context lifecycle”Event context is automatically cleared at the beginning of each web request in supported frameworks (Django, Flask). You can also manually clear it:
honeybadger.reset_event_context()Temporary context
Section titled “Temporary context”For temporary context that should only apply to specific operations, use the context manager:
with honeybadger.event_context(operation="batch_import"): # Context is only set within this block honeybadger.event("import.started") process_batch() honeybadger.event("import.completed")# Context is automatically restored when exiting the blockPrecedence
Section titled “Precedence”If both event context and event data contain the same key, the event data takes precedence:
honeybadger.set_event_context(service="api")honeybadger.event("order.created", service="checkout") # service="checkout" is used