Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scopes documentation for Java and Android #4747

Merged
merged 19 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1bb105b
Improve clarity for Local Scopes documentation
designedbyz Feb 19, 2022
2621110
Mention Kotlin Extensions in Android setup
designedbyz Feb 19, 2022
512c9e3
Cleanup sentry for android local scopes doc.
designedbyz Feb 19, 2022
4cd11c7
Hide local scopes from Android, show Kotlin
designedbyz Feb 19, 2022
85df56d
Extract scope synchronization from configure scope include
designedbyz Feb 19, 2022
52945f7
trigger build
imatwawana Feb 22, 2022
1d1fbe0
Fix accidentally excluded platform section
designedbyz Mar 1, 2022
014eaa2
Remove Local Scope information from Android docs
designedbyz Mar 8, 2022
70231d3
Only show Kotlin info for Java and Android
designedbyz Mar 8, 2022
59072db
Fix removing local scope for Android breaking a link in attachments.
designedbyz Mar 29, 2022
fb07118
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
74f8aa8
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
ba85cae
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
e146473
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
fb551f7
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
a1d24cf
Update src/platforms/common/enriching-events/scopes.mdx
marandaneto Apr 5, 2022
e2de2e3
Update src/includes/getting-started-install/android.mdx
marandaneto Apr 5, 2022
10b558e
Remove mention of kotlin extensions dependency from Android scopes info
designedbyz Apr 26, 2022
bc7165a
Merge branch 'master' into update-scopes
marandaneto Apr 26, 2022
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
10 changes: 0 additions & 10 deletions src/includes/enriching-events/scopes/configure-scope/android.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
<PlatformContent includePath="enriching-events/scopes/configure-scope/java.mdx" />

### Scope Synchronization

If you want to set context data in the Java layer, then receive that context data when a native (C/C++) crash happens, you need to synchronize the Java `Scope` with the native `Scope`. This feature was introduced in version `3.0.0` of the Android SDK and requires an opt-in:

```xml {filename:AndroidManifest.xml}
<application>
<meta-data android:name="io.sentry.ndk.scope-sync.enable" android:value="true" />
</application>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Sentry Android SDK doesn't support the concept of `Local Scopes`. A single `Scope` is used everwhere in the App's lifecycle.
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Scope Synchronization

If you want to set context data in the Java layer, then receive that context data when a native (C/C++) crash happens, you need to synchronize the Java `Scope` with the native `Scope`. This feature was introduced in version `3.0.0` of the Android SDK and requires an opt-in:
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

```xml {filename:AndroidManifest.xml}
<application>
<meta-data android:name="io.sentry.ndk.scope-sync.enable" android:value="true" />
</application>
```

This file was deleted.

2 changes: 2 additions & 0 deletions src/includes/getting-started-install/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ Sentry's Android SDK depends on [Gson](https://github.com/google/gson) as a tran

If you are using multiple Sentry dependencies, you can add a [bill of materials](/platforms/android/configuration/bill-of-materials) to avoid specifying the version of each dependency.

If you are using Kotlin and coroutines in your Android project, you should read [Using Sentry SDK with Coroutines](/platforms/android/enriching-events/scopes/#kotlin-coroutines)
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

</Note>
51 changes: 35 additions & 16 deletions src/platforms/common/enriching-events/scopes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ routes or controllers.
## How the Scope and Hub Work

As you start using an SDK, a scope and hub are automatically created for you out
of the box. You are unlikely to be interacting with the hub directly unless you
of the box. It is unlikely that you will interact with the hub directly unless you
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
are writing an integration or you want to create or destroy scopes. Scopes, on the
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
other hand are more user facing. You can at any point in time call
`configure-scope` to modify data stored on the scope. This is for instance
used to [modify the context](../context/).
other hand are more user facing. You may call `configure-scope` at any point in
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
time to to modify data stored on the scope. This is useful for doing things like
[modifying the context](../context/).

<Alert>
If you are very curious about how thread locality works: On platforms such as .NET
Expand Down Expand Up @@ -80,28 +80,48 @@ You can also apply this configuration when unsetting a user at logout:

<PlatformContent includePath="enriching-events/unset-user" />

<PlatformSection supported={["android"]}>

<PlatformContent includePath="enriching-events/scopes/scope-synchronization" />

</PlatformSection>

To learn what useful information can be associated with scopes see
[the context documentation](../context/).

## Local Scopes

We also have support for pushing and configuring a scope in one go. This is typically called `with-scope` or `push-scope` which is also very helpful if you only want to send data with one specific event. In the following example we are using that function to attach a `level` and a `tag` to only one specific error:
<PlatformSection supported={["java"]} notSupported={["android"]}>
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

We also support pushing and configuring a scope within a single call. This is typically
called `with-scope` or `push-scope` depending on the SDK, and is very helpful if
you only want to send data for one specific event. In the following example we use
`with-scope` to attach a `level` and a `tag` to only one specific error:

<PlatformContent includePath="enriching-events/scopes/with-scope" />

While this example looks similar to `configure-scope`, it's very different, in the sense that `configure-scope` actually changes the current active scope, all successive calls to `configure-scope`
will keep the changes.
While this example looks similar to `configure-scope`, it is actually very different.
Calls to `configure-scope` change the current active scope; all successive calls
to `configure-scope` will maintain previously set changes unless they are explicitly
unset.

`with-scope` on the other hand creates a clone of the current scope and the changes
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
made will stay isolated within the `with-scope` callback function. This allows you to
easily isolate pieces of context information to specific locations in your code or
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
even call `clear` to briefly remove all context information.

While on the other hand using `with-scope` creates a clone of the current scope
and will stay isolated until the function call is completed. So you can either
set context information in there that you don't want to be somewhere else or not
attach any context information at all by calling `clear` on the scope, while the
"global" scope remains unchanged.
<Alert level="info" title="Important">
Any exceptions that occur within the callback function for `with-scope` will not be
caught and all errors that occur will be silently ignored and *not* repoted.
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
</Alert>

</PlatformSection>

Keep in mind that `with-scope` will not capture any exceptions that happen inside its callback function,
and every error that happens there will be silently ignored and *not* reported.
<PlatformSection supported={["android"]}>

<PlatformSection supported={["java"]} notSupported={["android"]}>
<PlatformContent includePath="enriching-events/scopes/local-scope" />

</PlatformSection>

## Kotlin Coroutines

Expand Down Expand Up @@ -140,4 +160,3 @@ launch(SentryContext()) {
}
}
```
</PlatformSection>
marandaneto marked this conversation as resolved.
Show resolved Hide resolved