-
-
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
```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")) | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,13 +93,17 @@ 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> | ||
|
||
## Local Scopes | ||
|
||
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 | ||
called `with-scope`, `push-scope` or implemented as a function parameter on the capture methods, depending on the SDK. It's very helpful if | ||
you only want to send data for one specific event. | ||
|
||
<PlatformSection supported={["go", "java", "javascript", "native", "php", "python", "ruby", "rust"]}> | ||
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. How did we arrive at this list of supported platforms? Is it all that have a file in 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. Native just has 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. Yes, went through the platforms in the with-scope folder. Removing native sounds good to me. Will have a look if that has any implications. |
||
|
||
### Using `with-scope` | ||
|
||
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" /> | ||
|
@@ -123,6 +127,28 @@ caught, and all errors that occur will be silently ignored and **not** reported. | |
|
||
</PlatformSection> | ||
|
||
<PlatformSection supported={["apple", "dart", "dotnet", "java", "unreal"]}> | ||
|
||
### Using Scope Callback Parameter | ||
|
||
In the following example we use the scope callback parameter that is available for all `capture` methods to attach a `level` and a `tag` to only one specific error: | ||
|
||
<PlatformContent includePath="enriching-events/scopes/scope-callback-param" /> | ||
|
||
Before the callback is invoked the SDK creates a clone of the current scope, and the changes | ||
made will stay isolated within the callback function. This allows you to | ||
more easily isolate pieces of context information to specific locations in your code or | ||
even call `clear` to briefly remove all context information. | ||
|
||
<Alert level="info" title="Important"> | ||
|
||
Any exceptions that occur within the callback function for configuring a local scope will not be | ||
caught, and all errors that occur will be silently ignored and **not** reported. | ||
|
||
</Alert> | ||
|
||
</PlatformSection> | ||
|
||
<PlatformSection supported={["java"]} notSupported={["android"]}> | ||
|
||
## Kotlin Coroutines | ||
|
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.
Further down is an
<Alert>
explaining that exceptions inwithScope
will be ignored. If I'm not mistaken, the new local scope overloads don't behave the same way. I think they should. Can we please update the implementation to catch Exceptions aswithScope
does?https://github.com/getsentry/sentry-docs/pull/5136/files#diff-1b74f2288f1f938f1b7595fe4986f66d21eb90be88c3670334e42ca2520746d1R117-R122
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.
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
capture
methodsWDYT the correct behavior should be?
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.
I'll try to clarify
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.
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.