Skip to content

Commit

Permalink
Merge pull request #24 from kaizen-solutions/library-updates
Browse files Browse the repository at this point in the history
Library updates
  • Loading branch information
calvinlfer authored May 30, 2023
2 parents 78b88ff + 14e5db1 commit df31a23
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.17, 2.13.10, 3.2.2]
scala: [2.12.17, 2.13.10, 3.3.0]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sbtrelease.ReleaseStateTransformations._
inThisBuild {
val scala212 = "2.12.17"
val scala213 = "2.13.10"
val scala32 = "3.2.2"
val scala32 = "3.3.0"

Seq(
scalaVersion := scala32,
Expand Down Expand Up @@ -63,7 +63,7 @@ def mkModule(projectName: String) =
.settings(
name := s"trace4cats-zio-extras-$projectName",
organization := "io.kaizen-solutions",
organizationName := "kaizen-solutions",
organizationName := "kaizen-solutions"
)

lazy val root =
Expand Down Expand Up @@ -272,8 +272,8 @@ lazy val zioHttpExample =
val trace4cats = "io.janstenpickle"
Seq(
trace4cats %% "trace4cats-jaeger-thrift-exporter" % Versions.trace4CatsJaegarExporter,
"dev.zio" %% "zio-logging-slf4j" % "2.1.12",
"dev.zio" %% "zio-logging-slf4j-bridge" % "2.1.12",
"dev.zio" %% "zio-logging-slf4j" % Versions.zioLogging,
"dev.zio" %% "zio-logging-slf4j-bridge" % Versions.zioLogging,
"ch.qos.logback" % "logback-classic" % "1.4.7"
)
}
Expand Down Expand Up @@ -445,7 +445,7 @@ lazy val zioKafka =
mkModule("zio-kafka")
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio-kafka" % Versions.zioKafka,
"dev.zio" %% "zio-kafka" % Versions.zioKafka,
"io.github.embeddedkafka" %% "embedded-kafka" % Versions.kafkaEmbedded % Test
),
excludeDependencies ++= {
Expand All @@ -465,11 +465,11 @@ lazy val zioKafkaExamples = {
.settings(
libraryDependencies ++= Seq(
"io.janstenpickle" %% "trace4cats-jaeger-thrift-exporter" % Versions.trace4CatsJaegarExporter,
"dev.zio" %% "zio-logging-slf4j" % "2.1.12",
"ch.qos.logback" % "logback-classic" % "1.4.7"
"dev.zio" %% "zio-logging-slf4j" % Versions.zioLogging,
"ch.qos.logback" % "logback-classic" % "1.4.7"
)
)
.dependsOn(
zioKafka
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ object InMemorySpanCompleter {
)

def layer0(serviceName: String) =
ZLayer.scopedEnvironment[Any](
for {
z <- entryPoint(TraceProcess(serviceName))
(completer, entrypoint) = z
} yield ZEnvironment(completer, new ZEntryPoint(entrypoint))
)
ZLayer.scopedEnvironment[Any](
for {
z <- entryPoint(TraceProcess(serviceName))
(completer, entrypoint) = z
} yield ZEnvironment(completer, new ZEntryPoint(entrypoint))
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.kaizensolutions.trace4cats.zio.extras.fs2

import cats.effect.kernel.Resource.ExitCase
import fs2.*
import fs2.Stream
import io.kaizensolutions.trace4cats.zio.extras.{Spanned, ZTracer}
import trace4cats.model.{SpanKind, TraceHeaders}
import trace4cats.{ErrorHandler, ToHeaders}
import io.kaizensolutions.trace4cats.zio.extras.{Spanned, ZTracer}
import zio.interop.catz.*
import zio.{RIO, ZIO}

Expand Down
13 changes: 7 additions & 6 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ object Versions {
val trace4Cats = "0.14.2"
val trace4CatsJaegarExporter = "0.14.0"
val zio = "2.0.13"
val zioInteropCats = "23.0.0.5"
val zioHttp = "3.0.0-RC1"
val zioLogging = "2.1.13"
val zioInteropCats = "23.0.0.6"
val zioHttp = "3.0.0-RC2"
val http4s = "0.23.19"
val tapir = "1.3.0"
val tapir = "1.4.0"
val sttp = "3.8.15"
val virgil = "0.12.0"
val doobie = "1.0.0-RC2"
val skunk = "0.6.0-RC2"
val embeddedPostgres = "2.0.3"
val scribe = "3.11.1"
val zioKafka = "2.3.0"
val embeddedPostgres = "2.0.4"
val scribe = "3.11.5"
val zioKafka = "2.3.1"
val kafkaEmbedded = "3.4.0.1"
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.8.2
sbt.version = 1.8.3
Original file line number Diff line number Diff line change
Expand Up @@ -14,114 +14,107 @@ import zio.interop.catz.*
object TracedSessionSpec extends ZIOSpecDefault {
override def spec: Spec[TestEnvironment, Any] =
suite("Traced Session specification")(
test("parameters") {
ZIO.scoped {
test("parameters")(
ZIO.scoped(
for {
take <- ZIO.service[TakeSession]
session <- take.access
_ <- session.parameters.get
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(
spans.length == 1,
spans.exists(_.name == "skunk.parameters.get")
)
} yield assertTrue(spans.length == 1, spans.exists(_.name == "skunk.parameters.get"))
)
),
test("parameter")(
ZIO.scoped(
for {
take <- ZIO.service[TakeSession]
session <- take.access
_ <- session.parameter("server_version").head.compile.last
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == "skunk.parameter.server_version"))
)
),
test("transactionStatus")(
ZIO.scoped(
for {
take <- ZIO.service[TakeSession]
session <- take.access
_ <- session.transactionStatus.get
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == "skunk.transactionStatus.get"))
)
),
test("execute")(
ZIO.scoped(
for {
take <- ZIO.service[TakeSession]
session <- take.access
createTable = sql"CREATE TABLE abc (name varchar primary key)".command
_ <- session.execute(createTable)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == createTable.sql))
)
),
test("unique")(
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"SELECT 42".query(int4)
_ <- session.unique(query)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
} +
test("parameter") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
_ <- session.parameter("server_version").head.compile.last
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(
spans.length == 1,
spans.exists(_.name == "skunk.parameter.server_version")
)
}
} +
test("transactionStatus") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
_ <- session.transactionStatus.get
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(
spans.length == 1,
spans.exists(_.name == "skunk.transactionStatus.get")
)
}
} +
test("execute") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
createTable = sql"CREATE TABLE abc (name varchar primary key)".command
_ <- session.execute(createTable)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == createTable.sql))
}
} +
test("unique") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"SELECT 42".query(int4)
_ <- session.unique(query)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
} +
test("option") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables limit 0".query(name ~ name)
_ <- session.option(query)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
} +
test("stream") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables".query(name ~ name)
_ <- session.stream(query)(args = skunk.Void, chunkSize = 128).compile.drain
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
} +
test("prepare + stream") {
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables".query(name ~ name)
pq <- session.prepare(query)
_ <- pq.stream(args = skunk.Void, chunkSize = 128).compile.drain
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql), spans.exists(_.attributes.contains("prepared")))
}
),
test("option")(
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables limit 0".query(name ~ name)
_ <- session.option(query)
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
),
test("stream")(
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables".query(name ~ name)
_ <- session.stream(query)(args = skunk.Void, chunkSize = 128).compile.drain
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(spans.length == 1, spans.exists(_.name == query.sql))
}
),
test("prepare + stream")(
ZIO.scoped {
for {
take <- ZIO.service[TakeSession]
session <- take.access
query = sql"select schemaname, relname from pg_stat_sys_tables".query(name ~ name)
pq <- session.prepare(query)
_ <- pq.stream(args = skunk.Void, chunkSize = 128).compile.drain
sc <- ZIO.service[InMemorySpanCompleter]
spans <- sc.retrieveCollected
} yield assertTrue(
spans.length == 1,
spans.exists(_.name == query.sql),
spans.exists(_.attributes.contains("prepared"))
)
}
)
)
.provideShared(Database.live, InMemorySpanCompleter.layer("skunk-test")) @@
TestAspect.sequential @@
TestAspect.ignore // TODO: Fix flaky test
// @@ TestAspect.flaky
TestAspect.sequential
}
object Database {
import cats.effect.std.Console
Expand Down Expand Up @@ -153,7 +146,14 @@ object Database {

val live: RLayer[ZTracer, TakeSession] = {
val postgres: ZIO[Scope, Throwable, EmbeddedPostgres] =
ZIO.acquireRelease(ZIO.attempt(EmbeddedPostgres.start()))(ep => ZIO.attempt(ep.close()).ignoreLogged)
ZIO.acquireRelease(
ZIO.attempt(
EmbeddedPostgres
.builder()
.setCleanDataDirectory(false)
.start()
)
)(ep => ZIO.attempt(ep.close()).ignoreLogged)

ZLayer.scoped(postgres.flatMap(sessionPool))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object ExampleServerApp extends ZIOAppDefault {

val http: Http[Db & ZTracer, Throwable, Request, Response] =
Http.collectZIO[Request] {
case Method.GET -> !! / "plaintext" =>
case Method.GET -> Root / "plaintext" =>
ZTracer.withSpan("plaintext-fetch-db") { span =>
for {
sleep <- Random.nextIntBetween(1, 3)
Expand All @@ -24,10 +24,10 @@ object ExampleServerApp extends ZIOAppDefault {
.withStatus(Status.Ok)
}

case Method.GET -> !! / "fail" =>
case Method.GET -> Root / "fail" =>
ZIO.fail(new RuntimeException("Error"))

case Method.GET -> !! / "bad_gateway" =>
case Method.GET -> Root / "bad_gateway" =>
ZIO.succeed(Response.status(Status.BadGateway))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ object ZioHttpServerTracer {

http
.runHandler(request)
.mapError(Option(_))
.flatMap {
case Some(handler) =>
ZIO.succeed(
Expand Down
Loading

0 comments on commit df31a23

Please sign in to comment.