Skip to content

Commit

Permalink
Dependency Updates (#53)
Browse files Browse the repository at this point in the history
* Dependency updates

* Update microsite
  • Loading branch information
tomverran authored Feb 2, 2021
1 parent eb18ee6 commit 35b4cda
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 52 deletions.
28 changes: 14 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import microsites.MicrositesPlugin.autoImport.micrositeDescription

scalaVersion in ThisBuild := "2.13.1"
scalaVersion in ThisBuild := "2.13.4"

classLoaderLayeringStrategy in ThisBuild := ClassLoaderLayeringStrategy.ScalaLibrary

Expand All @@ -18,12 +18,12 @@ val common = Seq(
git.useGitDescribe := true,
libraryDependencies ++= Seq(
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
compilerPlugin("org.typelevel" % "kind-projector" % "0.11.0" cross CrossVersion.full),
"org.typelevel" %% "cats-core" % "2.1.1",
"org.typelevel" %% "cats-effect" % "2.1.2",
"org.scalatest" %% "scalatest" % "3.1.1" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.3" % Test,
"org.scalatestplus" %% "scalacheck-1-14" % "3.1.1.1" % Test
compilerPlugin("org.typelevel" % "kind-projector" % "0.11.3" cross CrossVersion.full),
"org.typelevel" %% "cats-core" % "2.3.1",
"org.typelevel" %% "cats-effect" % "2.3.1",
"org.scalatest" %% "scalatest" % "3.2.3" % Test,
"org.scalacheck" %% "scalacheck" % "1.15.2" % Test,
"org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % Test
),
)

Expand All @@ -32,12 +32,12 @@ lazy val metricsCommon = project
.enablePlugins(GitVersioning)
.settings(common :+ (name := "metrics-common"))

val log4catsVersion = "1.0.1"
val natchezVersion = "0.0.11"
val http4sVersion = "0.21.2"
val log4catsVersion = "1.1.1"
val natchezVersion = "0.0.19"
val http4sVersion = "0.21.16"
val circeVersion = "0.13.0"
val slf4jVersion = "1.7.30"
val fs2Version = "2.3.0"
val fs2Version = "2.5.0"

lazy val natchezDatadog = project
.in(file("natchez-datadog"))
Expand Down Expand Up @@ -110,14 +110,14 @@ lazy val natchezFs2 = project
.settings(common :+ (name := "natchez-fs2"))
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "kittens" % "2.0.0",
"org.typelevel" %% "kittens" % "2.2.1",
"org.tpolecat" %% "natchez-core" % natchezVersion,
"co.fs2" %% "fs2-core" % fs2Version
)
)

val silencerVersion = "1.6.0"
val doobieVersion = "0.8.8"
val silencerVersion = "1.7.1"
val doobieVersion = "0.10.0"
lazy val natchezDoobie = project
.in(file("natchez-doobie"))
.enablePlugins(GitVersioning)
Expand Down
1 change: 0 additions & 1 deletion docs/docs/docs/natchez-fs2.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ If the stream is cancelled the span will be closed automatically.
```scala mdoc
import cats.Monad
import cats.effect.{ExitCode, IO, IOApp}
import cats.syntax.functor._
import com.ovoenergy.effect.natchez.syntax._
import com.ovoenergy.effect.natchez.{AllocatedSpan, Slf4j}
import fs2._
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/docs/natchez-http4s.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object NatchezHttp4s extends IOApp {
/**
* We can then serve the routes as normal
*/
BlazeServerBuilder[IO]
BlazeServerBuilder[IO](global)
.bindHttp(8080, "0.0.0.0")
.withHttpApp(routes)
.withoutBanner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.ovoenergy.effect.natchez

import cats.data.OptionT
import cats.effect.{Resource, Sync}
import cats.syntax.apply._
import cats.syntax.functor._
import natchez.{EntryPoint, Kernel, Span, TraceValue}

import java.net.URI

/**
* Given to separate tracing integrations combine them by calling each one of them
* for all natchez operations. When producing kernels we merge the kernels for maximum compatibility
Expand All @@ -19,6 +22,12 @@ object Combine {
(s1.span(name), s2.span(name)).mapN[Span[F]](combineSpan[F])
def put(fields: (String, TraceValue)*): F[Unit] =
(s1.put(fields: _*), s2.put(fields: _*)).tupled.as(())
def traceId: F[Option[String]] =
OptionT(s1.traceId).orElseF(s2.traceId).value
def spanId: F[Option[String]] =
OptionT(s1.spanId).orElseF(s2.spanId).value
def traceUri: F[Option[URI]] =
OptionT(s1.traceUri).orElseF(s2.traceUri).value
}

def combine[F[_]: Sync](e1: EntryPoint[F], e2: EntryPoint[F]): EntryPoint[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cats.syntax.traverse._
import cats.instances.option._
import natchez.TraceValue.{BooleanValue, NumberValue, StringValue}

import java.net.URI
import java.util.concurrent.TimeUnit.NANOSECONDS

/**
Expand Down Expand Up @@ -43,6 +44,15 @@ case class DatadogSpan[F[_]: Sync: Clock](

def kernel: F[Kernel] =
ids.get.map(SpanIdentifiers.toKernel)

def traceId: F[Option[String]] =
ids.get.map(id => Some(id.traceId.toString))

def spanId: F[Option[String]] =
ids.get.map(id => Some(id.spanId.toString))

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

object DatadogSpan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class SpanIdentifiers(
object SpanIdentifiers {

private def randomAbsLong[F[_]: Sync]: F[Long] =
Sync[F].delay(scala.util.Random.nextLong.abs)
Sync[F].delay(scala.util.Random.nextLong().abs)

private def randomUUID[F[_]: Sync]: F[String] =
Sync[F].delay(UUID.randomUUID.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.ovoenergy.effect.natchez.Datadog.entryPoint
import com.ovoenergy.effect.natchez.DatadogTags.SpanType.{Cache, Db, Web}
import com.ovoenergy.effect.natchez.DatadogTags.spanType
import natchez.EntryPoint
import natchez.TraceValue.StringValue
import org.http4s.Request
import org.http4s.circe.CirceEntityDecoder._
import org.http4s.syntax.literals._
Expand Down Expand Up @@ -78,8 +77,8 @@ class DatadogTest extends AnyWordSpec with Matchers {

"Submit the right info to Datadog when closed" in {

val res = run(_.root("bar:res").use(_.put("k" -> StringValue("v")) >> IO.sleep(1.milli))).unsafeRunSync
val span = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync.flatten.head
val res = run(_.root("bar:res").use(_.put("k" -> "v") >> IO.sleep(1.milli))).unsafeRunSync()
val span = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync().flatten.head

span.name shouldBe "bar"
span.service shouldBe "test"
Expand All @@ -93,22 +92,22 @@ class DatadogTest extends AnyWordSpec with Matchers {

"Infer the right span.type from any tags set" in {
Inspectors.forAll(List(Web, Cache, Db)) { typ =>
val res = run(_.root("bar:res").use(_.put(spanType(typ)))).unsafeRunSync
val span = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync.flatten.head
val res = run(_.root("bar:res").use(_.put(spanType(typ)))).unsafeRunSync()
val span = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync().flatten.head
span.`type` shouldBe Some(typ)
}
}

"Submit multiple spans across multiple calls when span() is called" in {
val res = run(_.root("bar").use(_.span("subspan").use(_ => timer.sleep(1.second)))).unsafeRunSync
val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync.flatten
val res = run(_.root("bar").use(_.span("subspan").use(_ => timer.sleep(1.second)))).unsafeRunSync()
val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync().flatten
spans.map(_.traceId).distinct.length shouldBe 1
spans.map(_.spanId).distinct.length shouldBe 2
}

"Allow you to override the service name and resource with colons" in {
val res = run(_.root("svc:name:res").use(_ => IO.unit)).unsafeRunSync
val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync.flatten
val res = run(_.root("svc:name:res").use(_ => IO.unit)).unsafeRunSync()
val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync().flatten
spans.head.resource shouldBe "res"
spans.head.service shouldBe "svc"
spans.head.name shouldBe "name"
Expand All @@ -119,9 +118,9 @@ class DatadogTest extends AnyWordSpec with Matchers {
_.root("bar:res").use { root =>
root.put("foo" -> "bar") >> root.span("sub").use(_.put("baz" -> "qux"))
}
).unsafeRunSync
).unsafeRunSync()

val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync.flatten
val spans = res.flatTraverse(_.as[List[List[SubmittableSpan]]]).unsafeRunSync().flatten
val rootSpan = spans.find(_.name == "bar").get
val subSpan = spans.find(_.name == "sub").get

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SpanIdentifiersTest extends AnyWordSpec with Matchers with Checkers {
parent <- SpanIdentifiers.create[IO]
child <- SpanIdentifiers.child[IO](parent)
} yield parent -> child
).unsafeRunSync
).unsafeRunSync()

parent.parentId shouldBe None
child.traceId shouldBe parent.traceId
Expand All @@ -32,7 +32,7 @@ class SpanIdentifiersTest extends AnyWordSpec with Matchers with Checkers {
ids <- create[IO]
kernel <- fromKernel[IO](SpanIdentifiers.toKernel(ids))
} yield ids -> kernel
).unsafeRunSync
).unsafeRunSync()

kernel.traceId shouldBe original.traceId
kernel.traceToken shouldBe original.traceToken
Expand All @@ -41,11 +41,11 @@ class SpanIdentifiersTest extends AnyWordSpec with Matchers with Checkers {
}

"Succeed in converting from a kernel even if info is missing" in {
fromKernel[IO](Kernel(Map.empty)).attempt.unsafeRunSync should matchPattern { case Right(_) => }
fromKernel[IO](Kernel(Map("X-Trace-Token" -> "foo"))).unsafeRunSync.traceToken shouldBe "foo"
fromKernel[IO](Kernel(Map.empty)).attempt.unsafeRunSync() should matchPattern { case Right(_) => }
fromKernel[IO](Kernel(Map("X-Trace-Token" -> "foo"))).unsafeRunSync().traceToken shouldBe "foo"
}

"Ignore header case when extracting info" in {
fromKernel[IO](Kernel(Map("x-TRACe-tokeN" -> "foo"))).unsafeRunSync.traceToken shouldBe "foo"
fromKernel[IO](Kernel(Map("x-TRACe-tokeN" -> "foo"))).unsafeRunSync().traceToken shouldBe "foo"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.ovoenergy.effect.natchez

import cats.effect.concurrent.Ref
import cats.effect.{Blocker, ContextShift, IO, Resource}
import cats.syntax.functor._
import com.ovoenergy.effect.natchez.TracedTransactor.Traced
import doobie.h2.H2Transactor.newH2Transactor
import doobie.implicits._
Expand All @@ -12,6 +11,7 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import cats.syntax.flatMap._

import java.net.URI
import scala.concurrent.ExecutionContext.global

class TracedTransactorTest extends AnyWordSpec with Matchers {
Expand All @@ -31,6 +31,12 @@ class TracedTransactorTest extends AnyWordSpec with Matchers {
IO.pure(Kernel(Map.empty))
def put(fields: (String, TraceValue)*): IO[Unit] =
sps.update(s => s.dropRight(1) :+ s.last.copy(tags = s.last.tags ++ fields.toMap))
def traceId: IO[Option[String]] =
IO.pure(None)
def spanId: IO[Option[String]] =
IO.pure(None)
def traceUri: IO[Option[URI]] =
IO.pure(None)
}
a.run(spanMock).attempt.flatMap(_ => sps.get)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import fs2.concurrent.Queue
import fs2.{Pipe, Stream}
import natchez.{Kernel, Span, TraceValue}

import java.net.URI

/**
* A Natchez span that has been pre-allocated and will stay open
* until either the stream that created it terminates or you call submit
Expand Down Expand Up @@ -48,6 +50,12 @@ object AllocatedSpan {
createSpan(spn, F.uncancelable(F.attempt(task) >> submit))
def submit: F[Unit] =
submitTask
def traceId: F[Option[String]] =
spn.traceId
def spanId: F[Option[String]] =
spn.spanId
def traceUri: F[Option[URI]] =
spn.traceUri
}

/**
Expand All @@ -60,7 +68,7 @@ object AllocatedSpan {

object Traced {
implicit def traverse[F[_]]: Traverse[Traced[F, *]] =
cats.derived.semi.traverse[Traced[F, *]]
cats.derived.semiauto.traverse[Traced[F, *]]
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object Configuration {
def entity[F[_]: Sync](name: String): MessageReader[F] =
TagReader(
Kleisli { message =>
message.bodyAsText.compile.last
message.bodyText.compile.last
.map { body =>
body.map(b => name -> StringValue(b)).toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TracedClientTest extends AnyWordSpec with Matchers {
_ <- ep.continue("bar", kernel).use(http.named("foo").status(Request[TraceIO]()).run)
reqs <- client.requests
} yield reqs
).unsafeRunSync
).unsafeRunSync()

requests.forall(_.headers.exists(_.name.value === "X-Trace-Token")) shouldBe true
}
Expand All @@ -47,7 +47,7 @@ class TracedClientTest extends AnyWordSpec with Matchers {
_ <- ep.root("root").use(http.named("foo").status(Request[TraceIO]()).run)
reqs <- ep.spans
} yield reqs
).unsafeRunSync
).unsafeRunSync()

spans.length shouldBe 2
spans.head.name shouldBe "foo:http.request:/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import org.scalatest.Inspectors
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import java.net.URI

class TraceMiddlewareTest extends AnyWordSpec with Matchers with Inspectors {
type TraceIO[A] = Kleisli[IO, Span[IO], A]

Expand All @@ -28,6 +30,9 @@ class TraceMiddlewareTest extends AnyWordSpec with Matchers with Inspectors {
def kernel: F[Kernel] = Applicative[F].pure(Kernel(Map.empty))
def put(fields: (String, TraceValue)*): F[Unit] = ref.update(_ ++ fields.toMap)
def span(name: String): Resource[F, Span[F]] = Resource.pure(spanMock[F](ref))
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)
}

trait TestEntryPoint[F[_]] extends EntryPoint[F] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ovoenergy.effect.natchez

import java.util.UUID.randomUUID

import cats.Monad
import cats.data.OptionT
import cats.effect.concurrent.Ref
Expand All @@ -12,6 +11,8 @@ import natchez.TraceValue.StringValue
import natchez.{Kernel, Span, TraceValue}
import org.slf4j.{Logger, LoggerFactory, MDC}

import java.net.URI

case class Slf4jSpan[F[_]: Sync](
mdc: Ref[F, Map[String, TraceValue]],
logger: Logger,
Expand All @@ -27,6 +28,15 @@ case class Slf4jSpan[F[_]: Sync](

def span(name: String): Resource[F, Span[F]] =
Resource.liftF(mdc.get).flatMap(Slf4jSpan.create(name, Some(token), _)).widen

def traceId: F[Option[String]] =
Sync[F].pure(Some(token))

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

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

object Slf4jSpan {
Expand Down
Loading

0 comments on commit 35b4cda

Please sign in to comment.