You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two main ways to interact with the scope. You can access the current scope via `Sentry.getCurrentScope()` and use setters on the resulting scope, or you can use global methods like `Sentry.setTag()` directly, which will set on the respective scope under the hood (which will be the isolation scope).
109
+
In most cases, you should use top-level methods like `Sentry.setTag()` directly, which will set the data on the isolation scope, ensuring it is applied to all events related to the current request/process.
110
110
111
-
You'll first need to import the SDK, as usual:
111
+
If you want to apply data to a more narrow scope, you can use `withScope` to create a new scope that is only active for a specific part of your code. `withScope` receives the scope as a callback argument, which you can use to set data on the scope.
// Alternatively, you can use `withScope` as documented below.
132
125
```
133
126
134
127
To learn what useful information can be associated with scopes see
135
128
[context](../context/), [tags](../tags), [users](../identify-user) and [breadcrumbs](../breadcrumbs/).
136
129
130
+
We recommend you avoid using `getCurrentScope()` and setting data on it, as the current scope can have an unreliable lifetime. Instead:
131
+
132
+
* If you want to apply data to the current request/process (in Node) or the current page view (in browser), use the top-level methods, e.g. `Sentry.setTag()`.
133
+
* If you want to apply data to all events, no matter where they are captured, use methods on the global scope, e.g. `getGlobalScope().setTag()`
134
+
* If you want to apply data to a more narrow scope, use `withScope` to create a new scope that is only active for a specific part of your code.
135
+
137
136
## Using `withScope`
138
137
139
138
In the following example we use <PlatformIdentifiername="with-scope" /> to attach a `level` and a `tag` to only one specific error:
0 commit comments