Event context
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.
Request IDs from HTTP instrumentation
Section titled “Request IDs from HTTP instrumentation”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.
Clearing context
Section titled “Clearing context”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.
Precedence
Section titled “Precedence”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 eventNext.js edge runtime
Section titled “Next.js edge runtime”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.