Git Product home page Git Product logo

bayou's Introduction

Archived Natchez now supports tracing Resources and Streams out-of-the-box.

Bayou bayou Scala version support

An experimental extension of Natchez's Trace that supports tracing of Resource and Stream.

Bayou adds an additional method to the Trace API.

def spanR(name: String): Resource[F, Unit]

This creates a new span, and returns a Resource such that all effects run within the scope of the Resource are run within that span.

For example, vanilla span for a traced effect F may be implemented in terms of spanR.

def span[A](name: String)(k: F[A]): F[A] =
  spanR(name).use(_ => k)

But now it is also possible to span an entire Stream.

def span[A](name: String)(k: Stream[F, A]): Stream[F, A] =
  Stream.resource(spanR(name)).flatMap(_ => k)

Bayou's Trace fully interoperates with Natchez: bayou.Trace extends natchez.Trace and is implemented with natchez.Span.

What's the catch?

Bayou's Trace cannot be implemented with Kleisli; instead it is implemented for IO via IOLocal.

In practice, I believe this is not a problem, assuming that you initialize tracing early in your IOApp. Although this setup must be in concrete IO up until you have an instance of Trace[IO], your application logic from that point on may be written in terms of F[_]: Trace.

Furthermore, there are advantages to using IO as your traced effect.

  • No need to mapK between your untraced and traced effects, as they are both IO.
  • IOLocal has better performance than Kleisli and furthermore has no performance impact on untraced code.

One shortcoming of IOLocal-based tracing is that the root span must be installed upon creation. To mitigate this, Bayou offers an IOTrace class with additional methods that allow a different root span to be injected after-the-fact.

def span[A](span: Span[IO])(k: IO[A]): IO[A]

def spanR(span: Span[IO]): Resource[IO, Unit]

bayou's People

Contributors

armanbilge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bayou's Issues

Unexpected behavior with merging a traced Stream with another Stream

Merging a stream (.merge, .mergeHaltBoth, etc.) that uses bayou for tracing with another stream breaks the usage of child spans.

I know this project is just experimental, but I am also following the discussion of adding similar functionally to natchez so I figured I would share anyway. I have not pulled down and tested Ross' branch to verify the same behavior.

Merging a stream that uses bayou with another stream (even untraced streams) causes the underlying IOLocal to not properly update its state. I see no errors, but when I step through the debugger, the IOLocal will call set with the new Span[IO], but the next get still returns the default span. so every Trace[F] method acts upon the original root span used when instantiating the IOTrace. If the same stream is not merged with another, you can create and nest child spans as you would expect.

Here is an example of a single stream with its tracing output, which matches my expectations. (scala-cli https://gist.github.com/ryanmiville/6e4d756eceac70f9919c1de859e48f5a)

And here is the exact same stream merged with another stream, along with its traces. (scala-cli https://gist.github.com/ryanmiville/71d06f76dfe7c62ab96f342f5bed72b5)

Unfortunately, I don't know much about the inner workings of fs2 or IOLocal to provide any insight.

I don't expect you to really do anything about it, but I just wanted to bring it up in case the same behavior ends up making it into natchez, so it can at least be documented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.