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
Copy file name to clipboardExpand all lines: develop-docs/sdk/telemetry/spans/scopes.mdx
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,5 +6,55 @@ title: Scopes
6
6
This is work in progress and does not represent the final state.
7
7
</Alert>
8
8
9
+
The implementation in each SDK consists of three types of scopes:
10
+
11
+
- The global scope
12
+
- The isolation scope
13
+
- The current scope
14
+
15
+
Regardles of the scope type, data like tags, breadcrumbs, context, etc. can be added to each scope type by the user.
16
+
17
+
### Global Scope
18
+
19
+
The global scope acts as a global variable that stays the same for the entire execution of the application. Data applied to this scope will be applied to **all** events emitted by the SDK.
20
+
This scope is used for application-wide data like the `release`, the `environment`, etc.
21
+
22
+
### Isolation Scope
23
+
24
+
The isolation scope holds data which is only applicable to the current request (on a server), tab (in a browser), or user (on mobile). Top-level SDK APIs like `sentry.setTag()`, `sentry.setContext()`, etc. write to the isolation scope.
25
+
26
+
The isolation scope is stored in a context variable, thread local, async local, or similar depending on the platform.
27
+
28
+
The isolation scope is forked by the SDK's integrations. Users should not need to think about isolation scopes or forking of one.
29
+
30
+
### Current Scope
31
+
32
+
This scope holds data for the current active span. Whenever a new span is started the current scope of the parent span is forked (read: duplicated), giving the new span all the data from the parent span and making it possible to add or mutate data that is just applied to the new span (see also "Copy-on-write").
33
+
34
+
Changing the original scope after forking does not modify the forked scope.
35
+
36
+
The current scope is stored in a context variable, thread local, async local, or similar depending on the platform.
37
+
38
+
The current scope can be forked by the end user. Either explicitly, by using `sentry.withScope()` or implicitly, by starting a new span.
39
+
40
+
### The Scope APIs
41
+
42
+
```js
43
+
...
44
+
```
45
+
46
+
### Applying the scope data to events
47
+
48
+
The data held by all three scope types is merged before it is applied to an event.
49
+
50
+
This is performed in the following order:
51
+
52
+
1. Data from the global scope is...
53
+
2. merged with data from the isolation scope, which is...
54
+
3. merged with data from the current scope, which is ...
55
+
4. applied to the event
56
+
57
+
## Related Documents
58
+
9
59
This is a more concise version of the [Hub & Scope Refactoring](/sdk/miscellaneous/hub_and_scope_refactoring/) document. It does focus on the actual implementation and expected features.
10
60
The old document remains unchanged, and offers more historical context and migration strategies.
0 commit comments