Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/platforms/android/enriching-events/scopes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ Sentry.captureException(new Exception("my error"));
// --> Will have the following extra:
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
```
```kotlin
Sentry.configureScope(ScopeType.GLOBAL) { scope ->
scope.setExtra("shared", "global")
scope.setExtra("global", "data")
}

Sentry.configureScope(ScopeType.ISOLATION) { scope ->
scope.setExtra("shared", "isolation")
scope.setExtra("isolation", "data")
}

Sentry.configureScope(ScopeType.CURRENT) { scope ->
scope.setExtra("shared", "current")
scope.setExtra("current", "data")
}

Sentry.captureException(Exception("my error"))
// --> Will have the following extra:
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
```

## Configuring the Scope

Expand Down
40 changes: 39 additions & 1 deletion docs/platforms/java/common/enriching-events/scopes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ routes or request handlers.

## How Scopes Work

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

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.

Expand Down Expand Up @@ -54,6 +54,13 @@ Sentry.configureScope(ScopeType.ISOLATION, scope -> {
scope.setTag("my-tag", "my value");
});
```
```kotlin
Sentry.setTag("my-tag", "my value")
// Is identical to:
Sentry.configureScope(ScopeType.ISOLATION) { scope ->
scope.setTag("my-tag", "my value")
}
```

### Current Scope

Expand All @@ -70,6 +77,17 @@ Sentry.withScope(scope -> {
// this event will not have the tag:
Sentry.captureException(new Exception("my other error"));
```
```kotlin
Sentry.withScope { scope ->
// scope is the current scope inside of this callback!
scope.setTag("my-tag", "my value")
// this tag will only be applied to events captured inside of this callback
// the following event will have the tag:
Sentry.captureException(Exception("my error"))
}
// this event will not have the tag:
Sentry.captureException(Exception("my other error"))
```

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.

Expand Down Expand Up @@ -100,6 +118,26 @@ Sentry.captureException(new Exception("my error"));
// --> Will have the following extra:
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
```
```kotlin
Sentry.configureScope(ScopeType.GLOBAL) { scope ->
scope.setExtra("shared", "global")
scope.setExtra("global", "data")
}

Sentry.configureScope(ScopeType.ISOLATION) { scope ->
scope.setExtra("shared", "isolation")
scope.setExtra("isolation", "data")
}

Sentry.configureScope(ScopeType.CURRENT) { scope ->
scope.setExtra("shared", "current")
scope.setExtra("current", "data")
}

Sentry.captureException(Exception("my error"))
// --> Will have the following extra:
// { shared: 'current', global: 'data', isolation: 'data', current: 'data' }
```

## Configuring the Scope

Expand Down
Loading