-
-
Save rossabaker/160343ecbd2846df17761e5c6d26a9c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "2.13" | |
//> using lib "com.armanbilge::bayou:0.1-4fb42c8" | |
//> using lib "org.typelevel::cats-effect:3.3.7" | |
//> using lib "co.fs2::fs2-core:3.2.5" | |
//> using lib "org.typelevel::log4cats-core:2.2.0" | |
//> using lib "org.typelevel::log4cats-slf4j:2.2.0" | |
//> using lib "org.tpolecat::natchez-core:0.1.6" | |
//> using lib "org.tpolecat::natchez-log:0.1.6" | |
import cats.effect.{Trace => _, _} | |
import cats.implicits._ | |
import fs2._ | |
import bayou.Trace | |
import bayou.Trace._ | |
import natchez.log.Log | |
import natchez.{Trace => _, _} | |
import org.typelevel.log4cats.Logger | |
import org.typelevel.log4cats.slf4j.Slf4jLogger | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.global | |
import java.net.URI | |
trait Setup { | |
val entryPoint = Log.entryPoint[IO]("example") | |
val trace = entryPoint.root("root").flatMap(r => Resource.eval(Trace.ioTrace(r))) | |
implicit def logger: Logger[IO] = | |
new Logger[IO] { | |
def error(message: => String): IO[Unit] = | |
IO.println(s"[error] $message\n") | |
def warn(message: => String): IO[Unit] = | |
IO.println(s"[warn] $message\n") | |
def info(message: => String): IO[Unit] = | |
IO.println(s"[info] $message\n") | |
def debug(message: => String): IO[Unit] = | |
IO.println(s"[debug] $message\n") | |
def trace(message: => String): IO[Unit] = | |
IO.println(s"[trace] $message\n") | |
def error(t: Throwable)(message: => String): IO[Unit] = | |
IO.println(s"[error] $message\n${t.getMessage}") | |
def warn(t: Throwable)(message: => String): IO[Unit] = | |
IO.println(s"[warn] $message\n${t.getMessage}") | |
def info(t: Throwable)(message: => String): IO[Unit] = | |
IO.println(s"[info] $message\n${t.getMessage}") | |
def debug(t: Throwable)(message: => String): IO[Unit] = | |
IO.println(s"[debug] $message\n${t.getMessage}") | |
def trace(t: Throwable)(message: => String): IO[Unit] = | |
IO.println(s"[trace] $message\n${t.getMessage}") | |
} | |
} | |
object Single extends IOApp.Simple with Setup { | |
def run: IO[Unit] = { | |
trace.use { implicit trace => | |
for { | |
a <- trace.spanR("a").allocated | |
b <- trace.spanR("b").allocated | |
_ <- trace.put("1" -> "1") | |
_ <- a._2 | |
_ <- trace.put("2" -> "2") | |
_ <- b._2 | |
_ <- trace.put("3" -> "3") | |
} yield () | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name" : "root", | |
"service" : "example", | |
"timestamp" : "2022-03-09T01:45:00.675Z", | |
"duration_ms" : 213, | |
"trace.span_id" : "4493b161-624c-487a-9df7-7e348090331f", | |
"trace.parent_id" : null, | |
"trace.trace_id" : "d373716f-afcf-4f3b-8b89-3a49487c48d2", | |
"exit.case" : "succeeded", | |
"2" : "2", | |
"children" : [ | |
{ | |
"name" : "a", | |
"service" : "example", | |
"timestamp" : "2022-03-09T01:45:00.691Z", | |
"duration_ms" : 136, | |
"trace.span_id" : "0c951942-0a20-48ee-8756-148639a7cd79", | |
"trace.parent_id" : "d373716f-afcf-4f3b-8b89-3a49487c48d2", | |
"trace.trace_id" : "d373716f-afcf-4f3b-8b89-3a49487c48d2", | |
"exit.case" : "succeeded", | |
"children" : [ | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment