Most of these ideas are now in Natchez so this repo has been archived
An EXtension of NATCHez's Trace
that supports creating new roots and tracing of Resource
and Stream
.
The majority of this code is shamelessly copied from Bayou and this Natchez pull request.
Natchex adds a handful of methods to natchez.Trace
that should be intuitive for anyone familiar with Natchez's API.
trait Trace[F[_]] extends natchez.Trace[F] {
def root[A](name: String)(k: F[A]): F[A]
def continue[A](name: String, kernel: Kernel)(k: F[A]): F[A]
def continueOrElseRoot[A](name: String, kernel: Kernel)(k: F[A]): F[A]
def spanResource[A](name: String)(k: Resource[F, A]): Resource[F, A]
def spanStream[A](name: String)(k: Stream[F, A]): Stream[F, A]
}
The motivating use case for Trace
having the capability to create new roots is tracing an operation within an infinite Stream
, such as processing a batch of messages from an Apache Kafka topic.
When you create a new root, only spans within that new root's scope are attached to it. Once the scope is exited, the previous span takes over again.
Natchex's Trace
is only implemented for IO
. The Natchez pull request that inspired this project proves that it may be possible to support other F[_]
s, but I have no interest in case it constrains possible future features.
Just like natchez.Trace
, a Trace
must always have a current span. Trace.make
instantiates the Trace
with a no-op span. Make sure you create a new root before spawning child spans.