diff --git a/docs/platforms/android/enriching-events/scopes/index.mdx b/docs/platforms/android/enriching-events/scopes/index.mdx index f6ee529e430afe..cc78544b98c6e2 100644 --- a/docs/platforms/android/enriching-events/scopes/index.mdx +++ b/docs/platforms/android/enriching-events/scopes/index.mdx @@ -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 diff --git a/docs/platforms/java/common/enriching-events/scopes/index.mdx b/docs/platforms/java/common/enriching-events/scopes/index.mdx index 2e13f0b9ddd007..58e678cad75df4 100644 --- a/docs/platforms/java/common/enriching-events/scopes/index.mdx +++ b/docs/platforms/java/common/enriching-events/scopes/index.mdx @@ -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. @@ -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 @@ -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. @@ -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