---
title: Event context
description: Add custom metadata to events sent from your JavaScript application to Honeybadger Insights.
url: https://docs.honeybadger.io/lib/javascript/insights/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.

Caution

This will add the metadata to all events sent, so be careful not to include too much data. Try to keep it to simple key/value pairs.

```javascript
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

When [automatic HTTP instrumentation](https://docs.honeybadger.io/lib/javascript/insights/automatic-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

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

```javascript
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

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

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

## 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](https://docs.honeybadger.io/lib/javascript/integration/nextjs/#insights-instrumentation) section for related request ID behavior.

---

## Try Honeybadger for FREE

Intelligent logging, error tracking, and Just Enough APM™ in one dev-friendly platform. Find and fix problems before users notice.

[Start free trial](https://app.honeybadger.io/users/sign_up)

[See plans and pricing](https://www.honeybadger.io/plans/)
