Skip to content

Commit

Permalink
Library Upgrades
Browse files Browse the repository at this point in the history
- Scala to 2.13.14
- SBT to 1.10.0
- ZIO to 2.1.1
- ZIO Logging to 2.2.4
- ZIO HTTP to 3.0.0-RC7
- HTTP4S to 0.23.27
- Tapir to 1.10.7
- Skunk to 0.6.4

Co-authored-by: Sathish Mandapaka <sathish.mandapaka@gmail.com>
  • Loading branch information
calvinlfer and monadicbind committed May 24, 2024
1 parent 0cff177 commit bf9bfaa
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 61 deletions.
2 changes: 2 additions & 0 deletions aliases.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addCommandAlias("lint", "; scalafmtAll")
addCommandAlias("lintEnforce", "; scalafmtCheckAll")
42 changes: 21 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.typelevel.scalacoptions.ScalacOptions

inThisBuild {
val scala213 = "2.13.13"
val scala213 = "2.13.14"
val scala3 = "3.3.3"

Seq(
Expand Down Expand Up @@ -64,7 +64,7 @@ lazy val kindProjectorSettings = {

def mkModule(projectName: String) =
Project(projectName, file(projectName))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(name := s"trace4cats-zio-extras-$projectName")

lazy val root =
Expand Down Expand Up @@ -99,7 +99,7 @@ lazy val root =

lazy val core = project
.in(file("core"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-core",
organization := "io.kaizen-solutions",
Expand Down Expand Up @@ -127,7 +127,7 @@ lazy val core = project

lazy val coreExample = project
.in(file("core-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-core-examples",
publish / skip := true,
Expand All @@ -140,7 +140,7 @@ lazy val coreExample = project

lazy val fs2 = project
.in(file("fs2"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-fs2",
libraryDependencies += "co.fs2" %% "fs2-core" % Versions.fs2
Expand All @@ -149,7 +149,7 @@ lazy val fs2 = project

lazy val fs2Example = project
.in(file("fs2-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-fs2-examples",
publish / skip := true,
Expand All @@ -163,7 +163,7 @@ lazy val fs2Example = project
lazy val fs2Kafka =
project
.in(file("fs2-kafka"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-fs2-kafka",
libraryDependencies += "com.github.fd4s" %% "fs2-kafka" % Versions.fs2Kafka
Expand All @@ -173,7 +173,7 @@ lazy val fs2Kafka =
lazy val fs2KafkaExample =
project
.in(file("fs2-kafka-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-fs2-kafka-examples",
publish / skip := true,
Expand All @@ -191,7 +191,7 @@ lazy val fs2KafkaExample =

lazy val http4s = project
.in(file("http4s"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-http4s",
libraryDependencies ++= {
Expand All @@ -209,7 +209,7 @@ lazy val http4s = project
lazy val http4sExample =
project
.in(file("http4s-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-http4s-examples",
publish / skip := true,
Expand All @@ -229,7 +229,7 @@ lazy val http4sExample =
lazy val zioHttp =
project
.in(file("zio-http"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
tpolecatExcludeOptions += ScalacOptions.lintInferAny
) // zio-http's @@ causes this (Scala 2.13) unless explicitly typed
Expand All @@ -242,7 +242,7 @@ lazy val zioHttp =
lazy val zioHttpExample =
project
.in(file("zio-http-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
tpolecatExcludeOptions += ScalacOptions.lintInferAny
) // zio-http's @@ causes this (Scala 2.13) unless explicitly typed
Expand All @@ -264,7 +264,7 @@ lazy val zioHttpExample =
lazy val sttp =
project
.in(file("sttp"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-sttp",
libraryDependencies += "com.softwaremill.sttp.client3" %% "zio" % Versions.sttp,
Expand All @@ -276,7 +276,7 @@ lazy val sttp =
lazy val sttpExample =
project
.in(file("sttp-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-zio-sttp-examples",
publish / skip := true,
Expand All @@ -291,7 +291,7 @@ lazy val sttpExample =
lazy val tapir =
project
.in(file("tapir"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-tapir",
libraryDependencies ++=
Expand Down Expand Up @@ -324,7 +324,7 @@ lazy val tapirExample =
lazy val virgil =
project
.in(file("virgil"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-virgil",
libraryDependencies += "io.kaizen-solutions" %% "virgil-zio" % Versions.virgil
Expand All @@ -334,7 +334,7 @@ lazy val virgil =
lazy val virgilExample =
project
.in(file("virgil-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-virgil-examples",
libraryDependencies += "io.janstenpickle" %% "trace4cats-jaeger-thrift-exporter" % Versions.trace4CatsJaegarExporter,
Expand All @@ -345,7 +345,7 @@ lazy val virgilExample =
lazy val doobie =
project
.in(file("doobie"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-doobie",
libraryDependencies ++=
Expand All @@ -360,7 +360,7 @@ lazy val doobie =
lazy val doobieExample =
project
.in(file("doobie-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "doobie-examples",
publish / skip := true,
Expand All @@ -375,7 +375,7 @@ lazy val doobieExample =
lazy val skunk =
project
.in(file("skunk"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "trace4cats-zio-extras-skunk",
libraryDependencies ++=
Expand All @@ -394,7 +394,7 @@ lazy val skunk =
lazy val skunkExample =
project
.in(file("skunk-examples"))
.settings(kindProjectorSettings*)
.settings(kindProjectorSettings *)
.settings(
name := "skunk-examples",
publish / skip := true,
Expand Down
12 changes: 6 additions & 6 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ object Versions {
val trace4Cats = "0.14.7"
val trace4CatsJaegarExporter = "0.14.0"
val trace4CatsHttp4sCommon = "0.14.1"
val zio = "2.0.22"
val zioLogging = "2.2.3"
val zio = "2.1.1"
val zioLogging = "2.2.4"
val zioInteropCats = "23.1.0.2"
val zioHttp = "3.0.0-RC6"
val http4s = "0.23.26"
val tapir = "1.10.6"
val zioHttp = "3.0.0-RC7"
val http4s = "0.23.27"
val tapir = "1.10.7"
val sttp = "3.9.5"
val virgil = "1.0.5"
val doobie = "1.0.0-RC5"
val skunk = "0.6.3"
val skunk = "0.6.4"
val embeddedPostgres = "2.0.7"
val scribe = "3.13.4"
val zioKafka = "2.7.4"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.9.9
sbt.version = 1.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package io.kaizensolutions.trace4cats.zio.extras.sttp.examples

import io.kaizensolutions.trace4cats.zio.extras.{ZEntryPoint, ZTracer}
import io.kaizensolutions.trace4cats.zio.extras.sttp.SttpBackendTracer
import sttp.capabilities
import sttp.capabilities.zio.ZioStreams
import sttp.client3.*
import sttp.client3.httpclient.zio.HttpClientZioBackend
import zio.*

// Spin up the HTTP4S Server Example and then this one
object ExampleClientApp extends ZIOAppDefault {
type SttpClient = SttpBackend[Task, ZioStreams & capabilities.WebSockets]
type SttpClient = SttpBackend[Task, Any]

val tracedBackend: URIO[Scope & ZTracer, SttpClient] =
(for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import zio.*

object SttpBackendTracerSpec extends ZIOSpecDefault {

private val successBackend = SttpBackendStub(new RIOMonadAsyncError[Any])
.whenAnyRequest
private val successBackend = SttpBackendStub(new RIOMonadAsyncError[Any]).whenAnyRequest
.thenRespondOk()

private val ztracerEnv: ZIO[Scope, Nothing, ZEnvironment[InMemorySpanCompleter & ZTracer]] = for {
result <- InMemorySpanCompleter.entryPoint(TraceProcess("tapir-trace-interceptor-test"))
result <- InMemorySpanCompleter.entryPoint(TraceProcess("tapir-trace-interceptor-test"))
(sc, ep) = result
tracer <- InMemorySpanCompleter.toZTracer(ep)
tracer <- InMemorySpanCompleter.toZTracer(ep)
} yield ZEnvironment(sc).add(tracer)

val zioLogger = new Logger[Task] {
Expand All @@ -30,17 +29,15 @@ object SttpBackendTracerSpec extends ZIOSpecDefault {
}

def spec: Spec[TestEnvironment & Scope, Any] = suite("Sttp backend tracer")(
test("Traces requests"){
test("Traces requests") {
for {
tracer <- ZIO.service[ZTracer]
tracer <- ZIO.service[ZTracer]
completer <- ZIO.service[InMemorySpanCompleter]
backend = SttpBackendTracer(tracer,
LoggingBackend(successBackend, zioLogger)
)
backend = SttpBackendTracer(tracer, LoggingBackend(successBackend, zioLogger))
_ <- basicRequest
.get(uri"http://host/foo/bar")
.send(backend)
logs <- ZTestLogger.logOutput
.get(uri"http://host/foo/bar")
.send(backend)
logs <- ZTestLogger.logOutput
spans <- completer.retrieveCollected
} yield assertTrue(
logs.filter(_.message().contains("GET /foo/bar")).forall(_.annotations.contains("X-B3-TraceId")),
Expand All @@ -54,6 +51,6 @@ object SttpBackendTracerSpec extends ZIOSpecDefault {
).provide(
ZLayer.scopedEnvironment(
ztracerEnv
),
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ object TraceInterceptorSpec extends ZIOSpecDefault {
.prependInterceptor(interceptor)
.serverLog(
DefaultServerLog[Task](
doLogWhenReceived = ZIO.logInfo(_),
doLogWhenHandled = (msg, ex) => ex.fold(ZIO.logInfo(msg)) { ex => ZIO.logErrorCause(msg, Cause.fail(ex)) },
doLogAllDecodeFailures = (msg, ex) => ex.fold(ZIO.logWarning(msg)) { ex => ZIO.logWarningCause(msg, Cause.fail(ex)) },
doLogExceptions = (msg, ex) => ZIO.logErrorCause(msg, Cause.fail(ex)),
noLog = ZIO.unit
doLogWhenReceived = ZIO.logInfo(_),
doLogWhenHandled =
(msg, ex) => ex.fold(ZIO.logInfo(msg))(ex => ZIO.logErrorCause(msg, Cause.fail(ex))),
doLogAllDecodeFailures = (msg, ex) =>
ex.fold(ZIO.logWarning(msg))(ex => ZIO.logWarningCause(msg, Cause.fail(ex))),
doLogExceptions = (msg, ex) => ZIO.logErrorCause(msg, Cause.fail(ex)),
noLog = ZIO.unit
)
)
.options
).toRoutes(endpoint.serverLogic).orNotFound
response <- httpApp.run(Request(uri = uri"/hello/cal/greeting"))
spans <- sc.retrieveCollected
logs <- ZTestLogger.logOutput
logs <- ZTestLogger.logOutput
} yield assertTrue(
response.headers.get(CIString("traceparent")).isDefined,
response.status == Status.Ok,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ object ExampleServerApp extends ZIOAppDefault {
Method.GET / "bad_gateway" -> handler(ZIO.succeed(Response.status(Status.BadGateway)))
)

val app: HttpApp[Db & ZTracer] =
http.handleError(error => Response.text(error.getMessage).status(Status.InternalServerError)).toHttpApp
val app: Routes[Db with ZTracer, Nothing] =
http.handleError(error =>
Response
.text(error.getMessage)
.status(Status.InternalServerError)
)

override val run: ZIO[ZIOAppArgs & Scope, Any, Any] =
Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import zio.test.*

object ZioHttpServerTracerSpec extends ZIOSpecDefault {
val customHeaderName = "custom-header"
val testApp: HttpApp[ZTracer] =
val testApp =
Routes(
Method.GET / "plaintext" -> handler(
ZTracer.withSpan("plaintext-fetch") { _ =>
Expand All @@ -29,7 +29,7 @@ object ZioHttpServerTracerSpec extends ZIOSpecDefault {
.json(s"{ 'userId': '$userId', 'name': 'Bob' }")
.status(Status.Ok)
)
).toHttpApp
)

val spec: Spec[TestEnvironment & Scope, Any] =
suite("ZIO HTTP Server Tracer Specification")(
Expand All @@ -42,7 +42,7 @@ object ZioHttpServerTracerSpec extends ZIOSpecDefault {
.provideEnvironment(ZEnvironment.empty.add(tracer))
)
(completer, app) = result
response <- app.runZIO(Request.get(URL(Root / "plaintext")))
response <- app.runZIO(Request.get(URL(Path("plaintext"))))
spans <- completer.retrieveCollected
httpSpan <- ZIO.from(spans.find(_.name == "GET /plaintext"))
fetchSpan <- ZIO.from(spans.find(_.name == "plaintext-fetch"))
Expand All @@ -64,8 +64,8 @@ object ZioHttpServerTracerSpec extends ZIOSpecDefault {
(testApp @@ ZioHttpServerTracer.trace()).provideEnvironment(ZEnvironment.empty.add(tracer))
)
(completer, app) = result
_ <- app.runZIO(Request.get(URL(Root / "user" / "1234")))
_ <- app.runZIO(Request.get(URL(Root / "plaintext")))
_ <- app.runZIO(Request.get(URL(Path("user") / "1234")))
_ <- app.runZIO(Request.get(URL(Path("plaintext"))))
spans <- completer.retrieveCollected
_ <- ZIO
.from(spans.find(_.name == "GET /user/{userId}"))
Expand All @@ -82,22 +82,22 @@ object ZioHttpServerTracerSpec extends ZIOSpecDefault {
val app = Routes(
Method.GET / "" -> handler(ZIO.succeed(Response.ok)),
(Method.GET / "fail") -> handler(ZIO.fail(new RuntimeException("fail")))
).handleError(_ => Response.internalServerError).toHttpApp
).handleError(_ => Response.internalServerError)

val wrappedApp: HttpApp[ZTracer] =
val wrappedApp =
app @@ ZioHttpServerTracer.injectHeaders() @@ ZioHttpServerTracer.trace()

test("Succeeds on a successful response") {
for {
res <- wrappedApp.runZIO(Request.get(URL(Root)))
res <- wrappedApp.runZIO(Request.get(URL.empty))
spans <- InMemorySpanCompleter.retrieveCollected
httpHeadersFromSpan = toHttpHeaders(spans.head, ToHeaders.standard)
// This is done because assertTrue gets confused res.headers and res.headers(...)
responseHeaders = res.headers
} yield assertTrue(responseHeaders.toSeq.diff(httpHeadersFromSpan.toSeq).isEmpty)
} + test("Succeeds on a failing response")(
for {
resActual <- wrappedApp.runZIO(Request.get(URL(Root / "fail")))
resActual <- wrappedApp.runZIO(Request.get(URL(Path("fail"))))
spans <- InMemorySpanCompleter.retrieveCollected
expected = toHttpHeaders(spans.head, ToHeaders.standard)
} yield assertTrue(expected.toSet.subsetOf(resActual.headers.toSet))
Expand Down

0 comments on commit bf9bfaa

Please sign in to comment.