So. `IO.effect(IO.dispatchers().io() + MDCContext(...
# arrow
s
So.
IO.effect(IO.dispatchers().io() + MDCContext())
doesn’t work, but
IO.effect(MDCContext())
works. I am trying to put MDC correlation id on all the logs that gets produced on
IO.dispatchers().io()
s
Are the `id`s not getting added or it’s not running on the correct pool?
s
id
s are not getting added with
IO.dispatchers().io() + MDCContext()
Logs do get printed on right pool. for example,
whatever
log message from example above gets printed on
io-arrow-kt-worker-0
but with
IO.effect(MDCContext())
id
s get attach too
s
That’s super weird. If you click through on
+
you should be able to debug how the get added to each-other. It sounds like something is going wrong their and
IO.dispatchers().io() + MDCContext()
is resulting in the wrong combination of
CorotuineContext
Which is strange since
IO.dispatchers().io()
just uses the default impl from the std
s
I am on it
So I gets added, along arrow io worker. I am trying to look further what happens. Just putting it here if you find anything
s
Hmm that looks indeed correct. I’m not sure what’s going on there in that case 😕
Where and how are you launching the
IO
? I think it’s related to the KotlinX machinery, and that
ThreadContextElement
is not working correctly outside of KotlinX since it’s a libray.
You should be able to have it working with the KotlinX integration module that was published yesterday. Available under
Copy code
implementation "io.arrow-kt:arrow-fx-kotlinx-coroutines:0.10.5-SNAPSHOT"
This exposes
suspendCancelable
which uses the
Continuation
used by KotlinX under the hood instead of the
Continuation
from Kotlin’s standard library.
It also offers
unsafeRunScoped
to run `IO`’s within structured concurrency with
CoroutineScope
Using either of those methods should allow the KotlinX machinery to work again.
s
I actually skimmed through the PR which made this lib yesterday. Eagerly waiting for 0.10.5 to be released 😄
👍 1
by the way here is how I am trying it in ktor framework :
Copy code
fun Route.sendOk() {
        get("/status") {
            IO
                .invoke(IO.dispatchers().io()) {
                    <http://log.info|log.info>("whatever")
                }
                .flatMap { IO.effect(IO.dispatchers().io()) { this.call.respond("ok") } }
                .suspended()
        }
    }
this is just an example, so I would not use io pool to log one line
s
👍
Can you try using the snapshot version of that library and use
suspendCancelable
instead?
That way it’ll start on the KotlinX custom
Continuation
interface instead of the one from the standard library.
I think that’s necessary for their stuff to work. Which is what
ThreadContextElement<MDCContextMap>
does, since
ThreadContextElement
is not in the standard library put specific to Kotlinx sadly.
s
okay. instead of
suspended()
? Yes I can give it a try. I will post in some time how it went. And thank you again @simon.vergauwen ❤️
❤️ 2
s
Yes, exactly. You’re very welcome 🙂
s
It works yay!! Thank you so much 🙂
But I can’t use snapshots in production. So I’ll have to wait, unfortunately
s
Awesome, thanks for the update! We’re very actively working on the release. Should be released this month.
❤️ 1