-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Add CoroutineExceptionHandler
#4259
base: main
Are you sure you want to change the base?
Conversation
Performance metrics 🚀
|
sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryCoroutineExceptionHandler.kt
Show resolved
Hide resolved
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.
LGTM, though my familiarity with coroutines is limited. I'd say we get this into the hands of our customers to get some feedback. We can always iterate on it, especially since it's marked experimental for now.
sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryCoroutineExceptionHandler.kt
Show resolved
Hide resolved
sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryCoroutineExceptionHandler.kt
Show resolved
Hide resolved
I missed that part on my first review. We usually only report the error to Sentry but still pretend we're not there when it comes to exceptions. Not sure if the error handler design even allows us to do this here.
I believe that's just how Kotlin generates stack traces for coroutines and you need to reproduce with debug mode to have stacktrace recovery (https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/topics/debugging.md#stacktrace-recovery). @romtsn do you see potential in this where it makes sense to release it? It might be confusing our customers if this is the only Sentry exception handler that catches the exception for them. |
About the fact that it's being swallowed by the handler, we could also just rethrow it, but then it would show up twice in Sentry obviously. |
Yeah let's wait for @romtsn maybe we shouldn't merge this PR in its current state / feature set. |
If it's low maintenance for us (imo it is, the code is not gonna change much, and we don't have to introduce a new package for this), I think it's fine to ship it as-is and add docs. I guess it's no different from all the logging integrations we have, so people don't have to call And I also think it's fine that it prevents the app from crashing as this is how CoroutineExceptionHandler is designed, and folks who use it are aware of that behavior most likely (but ofc worth to mention in bold when adding docs). Since we also made the class |
|
||
override fun handleException(context: CoroutineContext, exception: Throwable) { | ||
val mechanism = Mechanism().apply { | ||
type = "CoroutineExceptionHandler" |
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.
we could also set handled = true
here I guess, because this is what the handler does, right?
Good points, thanks @romtsn ! |
📜 Description
Adds a
CoroutineExceptionHandler
, similar toUncaughtExceptionHandler
for exceptions thrown in coroutines.It can be used together with
SentryContext
when launching coroutines.💡 Motivation and Context
Closes #1524
I have tried https://github.com/Anamorphosee/stacktrace-decoroutinator as well but it doesn't really improve the stack trace and also only supports being enabled using a plugin in Android.
💚 How did you test it?
Unit tests and manual test in the UI triggered by button in Android app
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps
Update the docs