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, AWS Lambda, and Next.js (Node runtime) seed request_id and correlation_id onto the event context for each request. Custom keys you set with setEventContext merge alongside those IDs.

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

On the Next.js edge runtime, the client uses a shared global store. Do not rely on setEventContext for custom keys there — concurrent requests can overlap. Prefer attaching fields directly on Honeybadger.event(...) payloads instead. See the Next.js Insights instrumentation section for related request ID behavior.