micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.05k stars 1.06k forks source link

Coroutine Tracing Context Propagation Docs Outdated #9392

Open scprek opened 1 year ago

scprek commented 1 year ago

Issue description

I expect there to be information about how Tracing context is passed to coroutines and in the micronaut core docs there is a section https://docs.micronaut.io/latest/guide/index.html#coroutineTracingContextPropagation which references the class CoroutineTracingDispatcher that no longer exists. I assume this was due to the launch of https://micronaut-projects.github.io/micronaut-tracing/latest/guide/ and it's unclear to me if a context still needs to be added or not.

doppleware commented 5 months ago

Was this ever resolved?

scprek commented 5 months ago

I don’t think so, I ended up just writing extensions like this in a shared library for teams to use.


import io.opentelemetry.context.Context
import io.opentelemetry.extension.kotlin.asContextElement
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.slf4j.MDCContext

/**
 * Modifies the defaults of [runBlocking] by automatically including the [MDCContext] and [asContextElement] of OTEL
 * and using the Blocking Thread
 */
fun <T> runBlockingWithContext(context: CoroutineContext = Dispatchers.IO + MDCContext() + Context.current().asContextElement(), block: suspend CoroutineScope.() -> T): T {
    return runBlocking(context, block)
}
doppleware commented 5 months ago

Thanks for sharing this! I'm still trying to hack it into working, I'll report if I make a breakthrough ...

sdelamo commented 5 months ago

@dstepanov can you document this and fix the docs?