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: docs/platforms/java/common/enriching-events/scopes/index.mdx
+39-1Lines changed: 39 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ routes or request handlers.
21
21
22
22
## How Scopes Work
23
23
24
-
Scopes are basically a stacks of data that are attached to events. When an event is captured, the SDK will merge the data from the active scopes into the event. This allows you to attach data to events that is relevant to the context in which the event was captured.
24
+
Scopes are basically stacks of data that are attached to events. When an event is captured, the SDK will merge the data from the active scopes into the event. This allows you to attach data to events that is relevant to the context in which the event was captured.
25
25
26
26
A scope is generally valid inside of a callback or an execution context. This means that multiple parts of your application may have different scopes active at the same time. For instance, a web server might handle multiple requests at the same time, and each request may have different scope data to apply to its events.
Sentry.captureException(newException("my other error"));
72
79
```
80
+
```kotlin
81
+
Sentry.withScope { scope ->
82
+
// scope is the current scope inside of this callback!
83
+
scope.setTag("my-tag", "my value")
84
+
// this tag will only be applied to events captured inside of this callback
85
+
// the following event will have the tag:
86
+
Sentry.captureException(Exception("my error"))
87
+
}
88
+
// this event will not have the tag:
89
+
Sentry.captureException(Exception("my other error"))
90
+
```
73
91
74
92
You can modify the current scope via `Sentry.configureScope(ScopeType.CURRENT, scope -> { ... })`, but usually you should use `Sentry.withScope()` to interact with local scopes instead.
0 commit comments