Skip to content

Context propagation lost when using coroutines #1308

@simplekjl

Description

@simplekjl

Description

I've hit on a crucial and subtle point about tracing in a multi-threaded, multi-client environment.
When different auth-token requirements exist, we cannot use a single shared OkHttpClient; each client needs its own configuration.
The bigger issue, however, is that spans are not linking correctly due to how context is managed across different threads with Kotlin coroutines.
I have added the following:

runBlocking(ioDispatcher + Context.current().asContextElement()) {
     // tasks
}

Expected Behavior

The active span context should propagate correctly to child coroutines and OkHttp interceptors, so that spans are properly linked.

Actual Behavior

Context is lost when switching threads in runBlocking, causing spans to appear disconnected (no parent span).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions