-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 Local Scope Documentation #5136
Changes from 1 commit
29f4570
5f8f0d2
715fa08
12e870a
e85f78b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,96 @@ | ||
<PlatformSection supported={["android"]}> | ||
|
||
```java {tabTitle: Java} | ||
import io.sentry.Sentry; | ||
import io.sentry.SentryLevel; | ||
|
||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(new Exception("my error"), scope -> { | ||
scope.setTag("my-tag", "my value"); | ||
scope.setLevel(SentryLevel.WARNING); | ||
}); | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(new Exception("my error")); | ||
``` | ||
|
||
```kotlin {tabTitle: Kotlin} | ||
import io.sentry.Sentry | ||
import io.sentry.SentryLevel | ||
|
||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(Exception("my error")) { scope -> | ||
scope.setTag("my-tag", "my value") | ||
scope.level = SentryLevel.WARNING | ||
} | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(Exception("my error")) | ||
``` | ||
|
||
</PlatformSection> | ||
|
||
<PlatformSection notSupported={["android"]}> | ||
|
||
The JavaSDK provides two alternative ways of configuring a local scope. | ||
|
||
```java {tabTitle: Java} | ||
import io.sentry.Sentry; | ||
import io.sentry.SentryLevel; | ||
|
||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(new Exception("my error"), scope -> { | ||
scope.setTag("my-tag", "my value"); | ||
scope.setLevel(SentryLevel.WARNING); | ||
}); | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(new Exception("my error")); | ||
``` | ||
|
||
```java {tabTitle: Java-Alternative} | ||
import io.sentry.Sentry; | ||
import io.sentry.SentryLevel; | ||
|
||
Sentry.withScope(scope -> { | ||
scope.setLevel(SentryLevel.FATAL); | ||
scope.setTransaction("main"); | ||
scope.setTag("my-tag", "my value"); | ||
scope.setLevel(SentryLevel.WARNING); | ||
|
||
// This message includes the dataset to the scope in this block: | ||
Sentry.captureMessage("Fatal message!"); | ||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(new Exception("my error")); | ||
}); | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(new Exception("my error")); | ||
``` | ||
|
||
```kotlin {tabTitle: Kotlin} | ||
import io.sentry.Sentry | ||
import io.sentry.SentryLevel | ||
|
||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(Exception("my error")) { scope -> | ||
scope.setTag("my-tag", "my value") | ||
scope.level = SentryLevel.WARNING | ||
} | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(Exception("my error")) | ||
``` | ||
|
||
```kotlin {tabTitle: Kotlin-Alternative} | ||
import io.sentry.Sentry | ||
import io.sentry.SentryLevel | ||
|
||
Sentry.withScope { scope -> | ||
scope.level = SentryLevel.FATAL | ||
scope.setTransaction("main") | ||
scope.setTag("my-tag", "my value") | ||
scope.level = SentryLevel.WARNING | ||
|
||
// This message includes the dataset to the scope in this block: | ||
Sentry.captureMessage("Fatal message!") | ||
// will be tagged with my-tag="my value" | ||
Sentry.captureException(Exception("my error")) | ||
} | ||
|
||
// will not be tagged with my-tag | ||
Sentry.captureException(Exception("my error")) | ||
``` | ||
</PlatformSection> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ You can also apply this configuration when unsetting a user at logout: | |
To learn what useful information can be associated with scopes see | ||
[the context documentation](../context/). | ||
|
||
<PlatformSection notSupported={["android"]}> | ||
<PlatformSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now shows the default "Local Scope" section for Android which mentions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not exactly, it shows the same doc (like all SDKs), but only the code example for the callback (like dotnet). Java on the other hand has code examples for both the old and the new version. However, as mentioned above, we do have a discrepancy in the SDKs anyways. Some use an enclosure like the original java withScope and some use a callback-based approach on the capture methods directly. In my opinion we should have 2 Sections for LocalScope something like
and show them for the relevant SDKs. Because the current doc doesn't really make sense for all the Callback based SDKs. For Java we could show both sections in the meantime. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Java we could also show an alert that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'd move the current docs into a subheading and have a sibling subheading for the maybe like this:
Warning sounds good as well. |
||
|
||
## Local Scopes | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Further down is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we do have a bit of a discrepancy between the SDKs that use the callback parameter in this case: cocoa and dart don't capture exceptions that are thrown within the callback, while dotnet and java do because they invoke the callback within the try/catch of the respective WDYT the correct behavior should be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to clarify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created this getsentry/sentry-java#2123 to keep track of it. It's not blocking this PR just noticed this here and didn't wanna drop it. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.