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, 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.
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 event