Skip to content

Commit 1ea043d

Browse files
committed
Document automatic context propagation
Closes gh-35689
1 parent 24b5065 commit 1ea043d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

framework-docs/modules/ROOT/pages/languages/kotlin/coroutines.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ The {spring-framework-api-kdoc}/spring-core/org.springframework.core/-propagatio
264264
{micrometer-context-propagation-docs}/[Micrometer Context Propagation library] works with Kotlin Coroutines.
265265

266266
It requires the `io.micrometer:context-propagation` dependency and optionally the
267-
`org.jetbrains.kotlinx:kotlinx-coroutines-reactor` one.
267+
`org.jetbrains.kotlinx:kotlinx-coroutines-reactor` one. Automatic context propagation via
268+
`CoroutinesUtils#invokeSuspendingFunction` (used by Spring to adapt Coroutines to Reactor `Flux` or `Mono`) can be
269+
enabled by invoking `Hooks.enableAutomaticContextPropagation()`.
268270

269-
Applications can then use the `PropagationContextElement` to augment the `CoroutineContext`
271+
Applications can also use `PropagationContextElement` explicitly to augment the `CoroutineContext`
270272
with the context propagation mechanism:
271273

272274
include-code::./ContextPropagationSample[tag=context,indent=0]

framework-docs/src/main/kotlin/org/springframework/docs/languages/kotlin/coroutines/propagation/ContextPropagationSample.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class ContextPropagationSample {
3434
// tag::context[]
3535
fun main() {
3636
runBlocking(Dispatchers.IO + PropagationContextElement()) {
37-
suspendingFunction()
37+
waitAndLog()
3838
}
3939
}
4040

41-
suspend fun suspendingFunction() {
42-
delay(1)
41+
suspend fun waitAndLog() {
42+
delay(10)
4343
logger.info("Suspending function with traceId")
4444
}
4545
// end::context[]

0 commit comments

Comments
 (0)