I feel like when code uses coroutines my stack tra...
# coroutines
c
I feel like when code uses coroutines my stack traces don’t actually lead down to the part in my code at all. Am I doing something wrong? Is there just some flag we can enable for better stacktraces with coroutines? i feel like im going crazy here lol
r
c
It's normal, by default stacktraces will only go back to the coroutine source (e.g. nearest
launch
). In your tests, you should definitely enable the KotlinX.Coroutines debug agent. There are multiple ways to do that, but the most robust one is this mess (replace
target
by
project
). If that's still not enough, then definitely try the Decoroutinator, linked above. Both of these only help on the JVM
c
Yeah, I’m on android. I’m not in test code. Trying to fix production code with stacktraces from crashlytics
c
Ah, yeah
You can still enable the debug agent in production, but there's a small performance impact. I don't know about the performance of Decoroutinator
r
Small correction: Decoroutinator isn’t JVM-only. The JVM agent approach doesn’t work on Android, since Android has no Instrumentation API, but Decoroutinator supports Android through its Gradle plugin. Also, a lot of work has gone into keeping its performance overhead minimal, so it’s designed to be enabled in production too, not just in tests.
c
BUT I also write ios apps with kmp/cmp and so it would be cool to have a solution for that.
“so it’s designed to be enabled in production” excellent! I haven’t looked at it yet, but i wonder if i can enable it for only certain coroutines, etc. i will look into it when im back at my desk.
r
> BUT I also write ios apps with kmp/cmp and so it would be cool to have a solution for that. I have a few ideas for porting Decoroutinator to Kotlin/Native, which would bring it to iOS as well. But I'm not sure yet if or when it'll happen.