Skip to content

Commit 66c81c0

Browse files
authored
Add Kotlin examples and fix typo in Java and Android Scopes docs (#12458)
1 parent 424675e commit 66c81c0

File tree

2 files changed

+59
-1
lines changed
  • docs/platforms

2 files changed

+59
-1
lines changed

docs/platforms/android/enriching-events/scopes/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ Sentry.captureException(new Exception("my error"));
7070
// --> Will have the following extra:
7171
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
7272
```
73+
```kotlin
74+
Sentry.configureScope(ScopeType.GLOBAL) { scope ->
75+
scope.setExtra("shared", "global")
76+
scope.setExtra("global", "data")
77+
}
78+
79+
Sentry.configureScope(ScopeType.ISOLATION) { scope ->
80+
scope.setExtra("shared", "isolation")
81+
scope.setExtra("isolation", "data")
82+
}
83+
84+
Sentry.configureScope(ScopeType.CURRENT) { scope ->
85+
scope.setExtra("shared", "current")
86+
scope.setExtra("current", "data")
87+
}
88+
89+
Sentry.captureException(Exception("my error"))
90+
// --> Will have the following extra:
91+
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
92+
```
7393

7494
## Configuring the Scope
7595

docs/platforms/java/common/enriching-events/scopes/index.mdx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ routes or request handlers.
2121

2222
## How Scopes Work
2323

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.
2525

2626
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.
2727

@@ -54,6 +54,13 @@ Sentry.configureScope(ScopeType.ISOLATION, scope -> {
5454
scope.setTag("my-tag", "my value");
5555
});
5656
```
57+
```kotlin
58+
Sentry.setTag("my-tag", "my value")
59+
// Is identical to:
60+
Sentry.configureScope(ScopeType.ISOLATION) { scope ->
61+
scope.setTag("my-tag", "my value")
62+
}
63+
```
5764

5865
### Current Scope
5966

@@ -70,6 +77,17 @@ Sentry.withScope(scope -> {
7077
// this event will not have the tag:
7178
Sentry.captureException(new Exception("my other error"));
7279
```
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+
```
7391

7492
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.
7593

@@ -100,6 +118,26 @@ Sentry.captureException(new Exception("my error"));
100118
// --> Will have the following extra:
101119
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
102120
```
121+
```kotlin
122+
Sentry.configureScope(ScopeType.GLOBAL) { scope ->
123+
scope.setExtra("shared", "global")
124+
scope.setExtra("global", "data")
125+
}
126+
127+
Sentry.configureScope(ScopeType.ISOLATION) { scope ->
128+
scope.setExtra("shared", "isolation")
129+
scope.setExtra("isolation", "data")
130+
}
131+
132+
Sentry.configureScope(ScopeType.CURRENT) { scope ->
133+
scope.setExtra("shared", "current")
134+
scope.setExtra("current", "data")
135+
}
136+
137+
Sentry.captureException(Exception("my error"))
138+
// --> Will have the following extra:
139+
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
140+
```
103141

104142
## Configuring the Scope
105143

0 commit comments

Comments
 (0)