Skywalking with Kotlin coroutine
This Plugin provides an auto instrument support plugin for Kotlin coroutine based on context snapshot.
Description
SkyWalking provide tracing context propagation inside thread. In order to support Kotlin Coroutine, we provide this additional plugin.
Implementation principle
As we know, Kotlin coroutine switches the execution thread by CoroutineDispatcher
.
- Create a snapshot of the current context before dispatch the continuation.
- Then create a coroutine span after thread switched, mark the span continued with the snapshot.
- Every new span which created in the new thread will be a child of this coroutine span. So we can link those span together in a tracing.
- After the original runnable executed, we need to stop the coroutine span for cleaning thread state.
Some screenshots
Run without the plugin
We run a Kotlin coroutine based gRPC server without this coroutine plugin.
You can find, the one call (client -> server1 -> server2) has been split two tracing paths.
- Server1 without exit span and server2 tracing path.
- Server2 tracing path.
Run with the plugin
Without changing codes manually, just install the plugin. We can find the spans be connected together. We can get all info of one client call.