Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
massimosiani committed Aug 16, 2023
1 parent 1d65b76 commit 3830888
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import microsites.MicrositesPlugin.autoImport.micrositeDescription

val scala213Version = "2.13.8"
val scala3Version = "3.2.2"
val scala3Version = "3.3.0"

val scalaVersions = Seq(scala213Version, scala3Version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IOLocalTrace(private val local: IOLocal[Span[IO]]) extends Trace[IO] {

override def span[A](name: String, options: Span.Options)(k: IO[A]): IO[A] =
local.get.flatMap {
_.span(name).use { span =>
_.span(name, options).use { span =>
scope(span)(k)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import cats.syntax.traverse._
object syntax {

implicit class StreamOps[F[_]: Sync, A](s: Stream[F, Traced[F, A]]) {
def evalMapNamed[B](name: String)(op: A => F[B]): Stream[F, Traced[F, B]] =
s.evalMap(t => t.traverse(a => t.span.span(name).use(_ => op(a))))
def evalMapNamed[B](name: String, options: Span.Options = Span.Options.Defaults)(
op: A => F[B]
): Stream[F, Traced[F, B]] =
s.evalMap(t => t.traverse(a => t.span.span(name, options).use(_ => op(a))))

def evalMapTraced[B](name: String)(op: A => Kleisli[F, Span[F], B]): Stream[F, Traced[F, B]] =
s.evalMap(t => t.traverse(a => t.span.span(name).use(op(a).run)))
def evalMapTraced[B](name: String, options: Span.Options = Span.Options.Defaults)(
op: A => Kleisli[F, Span[F], B]
): Stream[F, Traced[F, B]] =
s.evalMap(t => t.traverse(a => t.span.span(name, options).use(op(a).run)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object Slf4jSpan {
Sync[F]
.fromEither(
k.toHeaders
.find(_._1.toString.toLowerCase == "x-trace-token")
.find(_._1 == ci"x-trace-token")
.map(_._2)
.toRight(new Exception("Missing X-Trace-Token header"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ object TestEntryPoint {
Resource.makeCase(
Ref.of[F, List[(String, TraceValue)]](List.empty).map { ref =>
new TestSpan[F] {
def tags: F[List[(String, TraceValue)]] = ref.get
def span(newName: String): Resource[F, Span[F]] = makeSpan(newName, Some(name), kern)
def put(fields: (String, TraceValue)*): F[Unit] = ref.update(_ ++ fields)
def traceId: F[Option[String]] = F.pure(None)
def spanId: F[Option[String]] = F.pure(None)
def traceUri: F[Option[URI]] = F.pure(None)
def kernel: F[Kernel] = F.pure(kern)
override def tags: F[List[(String, TraceValue)]] = ref.get
override def put(fields: (String, TraceValue)*): F[Unit] = ref.update(_ ++ fields)
override def traceId: F[Option[String]] = F.pure(None)
override def spanId: F[Option[String]] = F.pure(None)
override def traceUri: F[Option[URI]] = F.pure(None)
override def kernel: F[Kernel] = F.pure(kern)
override def log(fields: (String, TraceValue)*): F[Unit] = put(fields: _*)
override def log(event: String): F[Unit] = log("event" -> TraceValue.StringValue(event))
override def attachError(err: Throwable, fields: (String, TraceValue)*): F[Unit] =
put(Tags.error(true) :: fields.toList: _*)
override def span(name: String, options: Span.Options): Resource[F, Span[F]] = span(name)
private def span(newName: String): Resource[F, Span[F]] = makeSpan(newName, Some(name), kern)
}
}
) { (span, ec) =>
Expand Down

0 comments on commit 3830888

Please sign in to comment.