Skip to content

Filtering events

View Markdown

You can ignore or modify events programmatically using Honeybadger.beforeEvent. Handlers run before an event is sent to Honeybadger. If a handler returns false (or a promise that resolves to false), the event will not be sent.

Handlers may be synchronous or asynchronous. They receive the fully assembled event payload (including merged event context) and may mutate it in place.

For example, you can ignore events based on the event type:

Honeybadger.beforeEvent((event) => {
if (event.event_type === "request.handled" && event.path === "/health") {
return false;
}
});

Or modify the event data before it is sent:

Honeybadger.beforeEvent((event) => {
event.user_id = 456;
});

Async handlers are supported:

Honeybadger.beforeEvent(async (event) => {
event.region = await lookupRegion();
});

Note: You can register multiple beforeEvent handlers. They run in registration order. If any of them return false, the event will not be sent. A handler that throws is logged and skipped; remaining handlers still run.

If you’d rather reduce event volume across the board instead of ignoring specific events, see Sampling events.