-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add docs about process isolation in Node SDK #11378
Open
mydea
wants to merge
4
commits into
master
Choose a base branch
from
fn/otel-scope-auto-isolation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
docs/platforms/javascript/common/enriching-events/process-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: Process Isolation | ||
description: "Learn more about how process isolation (or request 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> 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](../scopes/#using-withisolationscope). | ||
|
||
The following example shows how you can use `withIsolationScope` to attach data for 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")); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: I'm not sure if "Process" isolation is a good term for the heading. We worry about isolating certain jobs/tasks/requests within one process.
I'd rather call this page "Request Isolation" or more generally "Task Isolation". WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was also not 100% sure about this. My first instinct was also to go with
Request Isolation
but this does not really cover e.g. isolation background jobs 🤔 but maybe request isolation is still more understandable 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me, at least better than process isolation.
Maybe another angle to this: What about "Data Isolation"? I mean generally this page explains how to isolate data within a unit of work (job/task/request).