Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs2 Stream instrumentation #848

Open
iRevive opened this issue Nov 20, 2024 · 0 comments
Open

fs2 Stream instrumentation #848

iRevive opened this issue Nov 20, 2024 · 0 comments
Labels
tracing Improvements to tracing module

Comments

@iRevive
Copy link
Contributor

iRevive commented Nov 20, 2024

Currently, it's hard to instrument the fs2 stream properly.

Perhaps we can follow the trace4cats route and encode the stream as WriterT[Stream[F, *], Span[F], A]:

type TracedStream[F[_]] = WriterT[Stream[F, *], Span[F], A]

implicit class StreamOps[F[_], A](private val s: Stream[F, A]) {
  def traced(name: String)(implicit A: Applicative[F], T: Tracer[F]): TracedStream[F, A] =
    Stream.bracket(Tracer[F].span(name).startUnmanaged)(_.end).flatMap { span =>
      s.evalMapChunk(a => Applicative[F].pure((span, a)))
    }
}

implicit class TracedStreamOps[F[_]](private val s: TracedStream[F, A]] {
  def evalMapTraced(name: String, attributes: Attributes): TracedStream[F, A] = ...
}

And a bunch of overloaded syntax methods.


But maybe there are better alternatives?

@iRevive iRevive added the tracing Improvements to tracing module label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracing Improvements to tracing module
Projects
None yet
Development

No branches or pull requests

1 participant