Skip to content

Event context

View Markdown

You can add custom metadata to the events sent to Honeybadger Insights by using Honeybadger.setEventContext. This metadata is merged into each event emitted within the current request (or async local storage scope) on Node.js runtimes.

Honeybadger.setEventContext({
user_id: user.id,
session_id: session.id,
});

Subsequent calls merge into the existing context rather than replacing it.

When automatic HTTP instrumentation is active, Express, Fastify, and AWS Lambda seed request_id and correlation_id onto the event context for each request. Custom keys you set with setEventContext merge alongside those IDs.

For Next.js, see Context on the server in the Next.js integration guide.

Clear event context when a request or unit of work is finished, or when values should no longer apply:

Honeybadger.clearEventContext();

Framework integrations that wrap each request typically isolate context per request via async local storage, so context from one request does not leak into another on Node.js.

If both event context and event data contain the same key, the event data takes precedence:

Honeybadger.setEventContext({ service: "api" });
Honeybadger.event("order.created", { service: "checkout" });
// service is "checkout" on the sent event