Request Isolation

Learn more about how request isolation (or process isolation) works in the Sentry SDK.

In server-side environments, the isolation scope automatically forks around request boundaries. This is done automatically by the SDK. As a result, each request has its own isolation scope, and data set on the isolation scope only applies to events captured during that request.

However, there are also other times when you may want to have isolation, for example, in background jobs or when you want to isolate a specific part of your code. In these cases, you can use Sentry.withIsolationScope() to create a new isolation scope that's valid inside of the callback you pass to it. Learn more about using withIsolationScope.

The following example shows how you can use withIsolationScope to attach data to a specific job run:

Copied
async function job(jobId) {
  return Sentry.withIsolationScope(async () => {
    // Only valid for events in this callback
    Sentry.setTag("jobId", jobId);
    await doSomething();
  });
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").