Add helpers to construct a Trace backed by a Ref#723
Add helpers to construct a Trace backed by a Ref#723mrdziuban wants to merge 2 commits intotrace4cats:masterfrom
Trace backed by a Ref#723Conversation
|
@mrdziuban Matt, thanks for the try! Unfortunately, this implementation just does not work in a concurrent environment. Using a global mutable variable (which is what a Ref is) being rewritten within local scopes is unsafe. This sample would show it: span("parent") {
printSpanId >>
List(
span("child1")(printSpanParentId),
span("child2")(printSpanParentId),
span("child3")(printSpanParentId),
span("child4")(printSpanParentId),
span("child5")(printSpanParentId)
).parSequence_
}If you run it against IO + Ref, it will spawn some child spans NOT from the parent span, which is incorrect. If you run it against Kleisli + IO, it will work correctly. |
|
Ahh okay, thanks for the feedback @catostrophe! Do you think an |
|
As for implementation via We did some work to allow one to use t4c with a compound context (let's name it I would also like to have it as a separate module since it's CE3-runtime-specific, and we depend only on ce3-kernel. |
|
Closing this one. You are welcome to open a PR with implementation via As I mentioned before, this should be a separate module. I thought again regarding |
Given a
Ref[F, Span[F]]we can product an instance ofLocal[F, Span[F]], which can be used to provide an implementation ofTrace[F]viaTrace.localSpanInstance[F, F]. This also adds supporting instances ofLift[F, F]andUnlift[F, F].This was inspired by natchez's
Trace.ioTracemethod. I was planning to add equivalents for constructing aTrace[IO]from anIOLocal[Span[IO]], butcats-effectisn't currently available in theinjectmodule. I think there are two approaches I could take to get it working, would you be okay with either?cats-effectas a dependency toinjectcats-effectmodule that depends oninjectand contains these helper methods