Transaction linking in co-routines when exceptions are thrown
anderssv opened this issue · 5 comments
Hi,
I am no expert with co-routines, so I am not sure if this should work or not, but to my limited understanding I think it should.
We are using KTor (which use co-routines heavily), and this extension made our world a lot better. Thanks. :) But it seems we are getting some weird behavior in cases where we throw exceptions.
Because the original routine suspended (see the code below), the catch of the exception (sometimes) resumes in a different thread. Then we get Transaction=Unknown for those cases. To my understanding this extension should handle co-routines jumping threads, but not really sure it is possible in the case of Exceptions? Using tokens to link in (in the catch clause), of course works.
The parallel code that is triggering this behavior is this:
suspend fun <A, B> Iterable<A>.parallelMap(concurrency: Int = 10, f: suspend (A) -> B): List<B> {
return coroutineScope {
val semaphore = Semaphore(concurrency)
map {
async {
semaphore.withPermit {
f(it)
}
}
}.awaitAll()
}
}
Exchanging a call to this function with a simple .map {} makes the weird behavior disappear.
So my question is really can/should this be handled? Right now it is throwing some of our error tracking and stats off. :)
Thanks,
Anders,
Anyone? Would really appreciate some feedback if there is something I should try to make this work. :)
I also saw DataDog had some issues (in their agent) with 1.5, is there an issue there? We're on 1.6.
Please note that as the README states, this extension is AS IS and unsupported but we do make a best effort to fix any problems that arise. We are a small team and as yet we have not had a chance to look into this issue.
The extension does attempt to track execution across threads and it is possible that in this particular case there is a gap in our coverage that does not track it across threads.
We will try to emulate this behavior into a test application and see if we can reproduce the problem. If we can identify the gap then we will attempt to fix it.
Thanks @dhilpipre . I totally get that this is not supported (I think NR should support Kotlin with coroutines though), so just wanted to see if there was anything I should try/change that you guys knew of.
If you have a public application for reproduction I would be happy to try and reproduce it there? I did try to have a look at the build/code setup of this extension, but it was a bit hard to get started by myself.
FYI: I raised this issue multiple times in the community forums as well and hope to push for full official support. Here are a couple of threads:
Fixed in current release