Hi, would you be interested in code to make it easier to work with tagless-final style FP programming, and with cats-effect (FP effect monad)?
The current tracing API is designed for Future users, and isn't very idiomatic for FP.
I would be thinking of something like:
An API for Span
e.g.
trait Span[F[_]] {
def spanContext: SpanContext
def end(implicit F: Sync[F]): F[Unit]
def addAnnotation(description: String)(implicit F: Sync[F]): F[Unit]
def openCensusSpan: io.opencensus.trace.Span
}
An API for creating spans
e.g.
trait SpanBuilder[F[_]] {
def rootSpan(spanName: String): F[Span[F]]
def spanWithRemoteParent(spanName: String,
parentSpanContext: Option[SpanContext]): F[Span[F]]
def spanWithLocalParent(spanName: String, parentSpan: Span[F]): F[Span[F]]
def threadLocalSpan: F[Span[F]]
}
An API for trace propagation which is similar to Kleisli, i.e. a wrapper around Span[F] => F[A]
e.g.
class Trace[F[_], A](val underlying: Span[F] => F[A]) extends AnyVal {
def withChildSpan(spanName: String)(
implicit F: Sync[F],
SpanBuilder: SpanBuilder[F]): Trace[F, A] =
Trace(
parentSpan =>
F.bracket(SpanBuilder.spanWithLocalParent(spanName, parentSpan))(
underlying)(_.end))
}
object Trace {
def apply[F[_], A](fa: Span[F] => F[A]): Trace[F, A] = new Trace(fa)
def apply[F[_], A](fa: Kleisli[F, Span[F], A]): Trace[F, A] = Trace(fa.run)
def liftF[F[_], A](fa: F[A]): Trace[F, A] = Trace(_ => fa)
}
An implementation of Trace for the Sync typeclass
(this provides map, flatMap, pure, delay, etc.)
e.g.
implicit def traceSyncInstance[F[_]](implicit F: Sync[F]): Sync[Trace[F, ?]] =
new Sync[Trace[F, ?]] {
...
}
Hi, would you be interested in code to make it easier to work with tagless-final style FP programming, and with cats-effect (FP effect monad)?
The current tracing API is designed for
Futureusers, and isn't very idiomatic for FP.I would be thinking of something like:
An API for Span
e.g.
An API for creating spans
e.g.
An API for trace propagation which is similar to
Kleisli, i.e. a wrapper aroundSpan[F] => F[A]e.g.
An implementation of
Tracefor theSynctypeclass(this provides
map,flatMap,pure,delay, etc.)e.g.