Process Isolation

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

In server-side environments, the isolation scope is automatically forked around request boundaries. This means that each request will have its own isolation scope, and data set on the isolation scope will only apply to events captured during that request. This is done automatically by the SDK.

However, there are also other cases where 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 is valid inside of the callback you pass to it - see Using withIsolationScope.

The following example shows how you can use withIsolationScope to attach data for 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").