-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add docs about request isolation in Node SDK (#11378)
--------- Co-authored-by: Lukas Stracke <[email protected]> Co-authored-by: Liza Mock <[email protected]>
- Loading branch information
1 parent
fdd67ba
commit b30fda8
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
docs/platforms/javascript/common/enriching-events/request-isolation/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Request Isolation | ||
description: "Learn more about how request isolation (or process isolation) works in the Sentry SDK." | ||
supported: | ||
- javascript.nextjs | ||
- javascript.node | ||
- javascript.connect | ||
- javascript.express | ||
- javascript.fastify | ||
- javascript.hapi | ||
- javascript.koa | ||
- javascript.nestjs | ||
- javascript.nuxt | ||
- javascript.solidstart | ||
- javascript.sveltekit | ||
- javascript.astro | ||
- javascript.remix | ||
notSupported: | ||
- javascript | ||
--- | ||
|
||
In server-side environments, the <PlatformLink to='/enriching-events/scopes'>isolation scope</PlatformLink> 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](../scopes/#using-withisolationscope). | ||
|
||
The following example shows how you can use `withIsolationScope` to attach data to a specific job run: | ||
|
||
```javascript | ||
async function job(jobId) { | ||
return Sentry.withIsolationScope(async () => { | ||
// Only valid for events in this callback | ||
Sentry.setTag("jobId", jobId); | ||
await doSomething(); | ||
}); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
platform-includes/enriching-events/scopes/with-isolation-scope/javascript.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
```javascript | ||
Sentry.withIsolationScope(function () { | ||
// This user & tag is set inside of this callback | ||
Sentry.setUser({ id: "123" }); | ||
Sentry.setTag("my-tag", "my value"); | ||
|
||
// will be tagged with my-tag="my value" & user | ||
Sentry.captureException(new Error("my error")); | ||
}); | ||
|
||
// will not be tagged with my-tag & user | ||
Sentry.captureException(new Error("my other error")); | ||
``` |