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

Empty Span #566

Closed
kubukoz opened this issue Jun 21, 2022 · 1 comment · Fixed by #666
Closed

Empty Span #566

kubukoz opened this issue Jun 21, 2022 · 1 comment · Fixed by #666

Comments

@kubukoz
Copy link
Member

kubukoz commented Jun 21, 2022

Hello! I've been using something like this to make Trace[IO] bearable:

def defaultSpan[F[_]: Applicative](ep: EntryPoint[F]): Span[F] =
  new Span[F] {
    def put(fields: (String, TraceValue)*): F[Unit] = Applicative[F].unit

    def kernel: F[Kernel] = Applicative[F].pure(Kernel(Map.empty))

    def span(name: String): Resource[F, Span[F]] = ep.root(name)

    def traceId: F[Option[String]] = Applicative[F].pure(None)

    def spanId: F[Option[String]] = Applicative[F].pure(None)

    def traceUri: F[Option[URI]] = Applicative[F].pure(None)

  }

The idea is that Trace.ioTrace requires a default Span that it starts from. The combined usage looks like this:

Trace.ioTrace(Spans.defaultSpan(ep)).flatMap { implicit ioTrace: Trace[IO] =>
  ...
}

You can do it once per app, at startup, and pass the Trace[IO] instance everywhere, which is very convenient and doesn't require any wrapping in Kleisli.

I'd happily contribute something similar, or even provide a shortcut that goes from EntryPoint[IO] straight to IO[Trace[IO]] (to avoid the question of what span to use as the default). Does this seem like a good idea?

@skirsdeda
Copy link

👍 Great idea! I was trying to find a sane way to use Trace[IO] with skunk Session being initialized only once in AWS Lambda for multiple requests (using feral). Thanks so much for posting this here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants