Skip to content

Commit

Permalink
Merge pull request #99 from ovotech/scala-3
Browse files Browse the repository at this point in the history
Scala 3
  • Loading branch information
voidcontext authored Apr 21, 2023
2 parents f3183db + f7b4782 commit 7447f37
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 68 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
command: |
set -e
tags=`git describe --tags`
sbt ';set version in ThisBuild := "'${tags}'"; test; publishSigned; sonatypeBundleRelease'
sbt ';set version in ThisBuild := "'${tags}'"; +test; +publishSigned; +sonatypeBundleRelease'
- *cache_save

test:
Expand All @@ -105,7 +105,7 @@ jobs:
- *install_sbt
- run:
name: Test
command: sbt test
command: sbt +test
- *cache_save

workflows:
Expand All @@ -117,7 +117,7 @@ workflows:
- release:
filters:
tags:
only: /^([0-9\\.]+(-RC[0-9]+)?)$/
only: /^([0-9\\.]+(-(RC|M)[0-9]+)?)$/
branches:
ignore: /.*/
pr-build:
Expand Down
107 changes: 59 additions & 48 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import microsites.MicrositesPlugin.autoImport.micrositeDescription

val scalaVer: String = "2.13.8"
val scala213Version = "2.13.8"
val scala3Version = "3.2.2"

ThisBuild / scalaVersion := scalaVer
val scalaVersions = Seq(scala213Version, scala3Version)

ThisBuild / organization := "com.ovoenergy"

Expand Down Expand Up @@ -44,6 +45,8 @@ val common = Seq(
libraryDependencies ++= Seq(
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full),
).filterNot(_ => scalaVersion.value.startsWith("3.")),
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.7.0",
"org.typelevel" %% "cats-effect" % "3.3.5",
"org.scalameta" %% "munit" % "0.7.29" % Test,
Expand All @@ -53,8 +56,9 @@ val common = Seq(
)
)

lazy val metricsCommon = project
lazy val metricsCommon = projectMatrix
.in(file("natchez-extras-metrics"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-metrics"))

Expand All @@ -70,7 +74,7 @@ val doobieVersion = "1.0.0-RC2"
lazy val natchezDatadog = projectMatrix
.in(file("natchez-extras-datadog"))
.customRow(
scalaVersions = Seq(scalaVer),
scalaVersions = scalaVersions,
axisValues = Seq(Http4sVersion.Milestone, VirtualAxis.jvm),
settings = List(
name := "natchez-extras-datadog",
Expand All @@ -82,7 +86,7 @@ lazy val natchezDatadog = projectMatrix
)
)
.customRow(
scalaVersions = Seq(scalaVer),
scalaVersions = scalaVersions,
axisValues = Seq(Http4sVersion.Stable, VirtualAxis.jvm),
settings = List(
name := "natchez-extras-datadog-stable",
Expand All @@ -100,14 +104,14 @@ lazy val natchezDatadog = projectMatrix
"org.tpolecat" %% "natchez-core" % natchezVersion,
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-generic-extras" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"org.slf4j" % "slf4j-api" % slf4jVersion
)
)

lazy val natchezSlf4j = project
lazy val natchezSlf4j = projectMatrix
.in(file("natchez-extras-slf4j"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-slf4j"))
.settings(
Expand All @@ -121,7 +125,7 @@ lazy val natchezSlf4j = project
lazy val natchezHttp4s = projectMatrix
.in(file("natchez-extras-http4s"))
.customRow(
scalaVersions = Seq(scalaVer),
scalaVersions = scalaVersions,
axisValues = Seq(Http4sVersion.Milestone, VirtualAxis.jvm),
settings = List(
name := "natchez-extras-http4s",
Expand All @@ -132,7 +136,7 @@ lazy val natchezHttp4s = projectMatrix
)
)
.customRow(
scalaVersions = Seq(scalaVer),
scalaVersions = scalaVersions,
axisValues = Seq(Http4sVersion.Stable, VirtualAxis.jvm),
settings = List(
name := "natchez-extras-http4s-stable",
Expand All @@ -142,7 +146,7 @@ lazy val natchezHttp4s = projectMatrix
)
)
)
.configure(_.dependsOn(natchezTestkit))
.dependsOn(natchezTestkit)
.enablePlugins(GitVersioning)
.settings(common)
.settings(
Expand All @@ -151,8 +155,9 @@ lazy val natchezHttp4s = projectMatrix
)
)

lazy val natchezLog4Cats = project
lazy val natchezLog4Cats = projectMatrix
.in(file("natchez-extras-log4cats"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-log4cats"))
.settings(
Expand All @@ -162,8 +167,9 @@ lazy val natchezLog4Cats = project
)
)

lazy val natchezTestkit = project
lazy val natchezTestkit = projectMatrix
.in(file("natchez-extras-testkit"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-testkit"))
.settings(
Expand All @@ -172,21 +178,23 @@ lazy val natchezTestkit = project
)
)

lazy val natchezFs2 = project
lazy val natchezFs2 = projectMatrix
.in(file("natchez-extras-fs2"))
.jvmPlatform(scalaVersions = scalaVersions)
.dependsOn(natchezTestkit)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-fs2"))
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "kittens" % "2.3.2",
"org.typelevel" %% "kittens" % "3.0.0-M4",
"org.tpolecat" %% "natchez-core" % natchezVersion,
"co.fs2" %% "fs2-core" % fs2Version
)
)

lazy val natchezDoobie = project
lazy val natchezDoobie = projectMatrix
.in(file("natchez-extras-doobie"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-doobie"))
.settings(
Expand All @@ -198,23 +206,26 @@ lazy val natchezDoobie = project
)
.dependsOn(core)

lazy val core = project
lazy val core = projectMatrix
.in(file("natchez-extras-core"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(
common ++ Seq(
name := "natchez-extras-core",
)
)

lazy val natchezCombine = project
lazy val natchezCombine = projectMatrix
.in(file("natchez-extras-combine"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-combine"))
.settings(libraryDependencies += "org.tpolecat" %% "natchez-core" % natchezVersion)

lazy val datadogMetrics = project
lazy val datadogMetrics = projectMatrix
.in(file("natchez-extras-dogstatsd"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-dogstatsd"))
.dependsOn(metricsCommon)
Expand All @@ -225,35 +236,39 @@ lazy val datadogMetrics = project
)
)

lazy val ce3Utils = project
lazy val ce3Utils = projectMatrix
.in(file("natchez-ce3"))
.jvmPlatform(scalaVersions = scalaVersions)
.enablePlugins(GitVersioning)
.settings(common :+ (name := "natchez-extras-ce3"))
.settings(libraryDependencies += "org.tpolecat" %% "natchez-core" % natchezVersion)

val logbackVersion = "1.2.3"

lazy val datadogStable = natchezDatadog.finder(Http4sVersion.Stable, VirtualAxis.jvm)(scalaVer)
lazy val datadogMilestone = natchezDatadog.finder(Http4sVersion.Milestone, VirtualAxis.jvm)(scalaVer)
lazy val datadogStable213 = natchezDatadog.finder(Http4sVersion.Stable, VirtualAxis.jvm)(scala213Version)
lazy val datadogMilestone213 =
natchezDatadog.finder(Http4sVersion.Milestone, VirtualAxis.jvm)(scala213Version)

lazy val natchezHttp4sStable = natchezHttp4s.finder(Http4sVersion.Stable, VirtualAxis.jvm)(scalaVer)
lazy val natchezHttp4sMilestone = natchezHttp4s.finder(Http4sVersion.Milestone, VirtualAxis.jvm)(scalaVer)
lazy val natchezHttp4sStable213 = natchezHttp4s.finder(Http4sVersion.Stable, VirtualAxis.jvm)(scala213Version)
lazy val natchezHttp4sMilestone213 =
natchezHttp4s.finder(Http4sVersion.Milestone, VirtualAxis.jvm)(scala213Version)

lazy val docs = project
.in(file("docs"))
.enablePlugins(MicrositesPlugin)
.dependsOn(
datadogMetrics,
natchezDoobie,
datadogStable,
natchezCombine,
natchezSlf4j,
natchezFs2,
natchezHttp4sStable,
natchezLog4Cats,
ce3Utils
ce3Utils.jvm(scala213Version),
datadogMetrics.jvm(scala213Version),
natchezDoobie.jvm(scala213Version),
datadogStable213,
natchezCombine.jvm(scala213Version),
natchezSlf4j.jvm(scala213Version),
natchezFs2.jvm(scala213Version),
natchezHttp4sStable213,
natchezLog4Cats.jvm(scala213Version)
)
.settings(
scalaVersion := scala213Version,
micrositeName := "natchez-extras",
micrositeBaseUrl := "/natchez-extras",
micrositeDocumentationUrl := "/natchez-extras/docs",
Expand Down Expand Up @@ -282,21 +297,17 @@ lazy val root = (project in file("."))
publish / skip := true
)
)
.aggregate(
core,
metricsCommon,
datadogMetrics,
datadogMilestone,
datadogStable,
natchezCombine,
natchezSlf4j,
natchezDoobie,
natchezLog4Cats,
natchezHttp4sMilestone,
natchezHttp4sStable,
natchezFs2,
natchezTestkit,
ce3Utils
)
.aggregate(core.projectRefs: _*)
.aggregate(ce3Utils.projectRefs: _*)
.aggregate(metricsCommon.projectRefs: _*)
.aggregate(datadogMetrics.projectRefs: _*)
.aggregate(natchezDatadog.projectRefs: _*)
.aggregate(natchezCombine.projectRefs: _*)
.aggregate(natchezSlf4j.projectRefs: _*)
.aggregate(natchezDoobie.projectRefs: _*)
.aggregate(natchezLog4Cats.projectRefs: _*)
.aggregate(natchezHttp4s.projectRefs: _*)
.aggregate(natchezFs2.projectRefs: _*)
.aggregate(natchezTestkit.projectRefs: _*)

Global / onChangedBuildSource := ReloadOnSourceChanges
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import cats.syntax.flatMap._
import cats.syntax.functor._
import cats.syntax.traverse._
import com.ovoenergy.natchez.extras.datadog.DatadogSpan.SpanNames
import io.circe.generic.extras.Configuration
import natchez.TraceValue.{BooleanValue, NumberValue, StringValue}
import natchez.{Kernel, Span, TraceValue}

Expand Down Expand Up @@ -79,9 +78,6 @@ object DatadogSpan {
}
}

implicit val config: Configuration =
Configuration.default.withSnakeCaseMemberNames

/**
* Given a span, complete it - this involves turning the span into a `CompletedSpan`
* which 1:1 matches the Datadog JSON structure before submitting it to a queue of spans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import cats.syntax.apply._
import com.ovoenergy.natchez.extras.datadog.DatadogTags.{forThrowable, SpanType}
import com.ovoenergy.natchez.extras.datadog.data.UnsignedLong
import io.circe.Encoder.encodeString
import io.circe.generic.extras.Configuration
import io.circe.generic.extras.semiauto._
import io.circe.{Decoder, Encoder}
import natchez.TraceValue
import natchez.TraceValue.StringValue
Expand All @@ -35,20 +33,58 @@ case class SubmittableSpan(

object SubmittableSpan {

implicit val config: Configuration =
Configuration.default.withSnakeCaseMemberNames

implicit val encodeSpanType: Encoder[SpanType] =
encodeString.contramap(_.toString.toLowerCase)

implicit val decodespanType: Decoder[Option[SpanType]] =
Decoder[Option[String]].map(_.flatMap(s => inferSpanType(Map("span.type" -> s))))

implicit val encode: Encoder[SubmittableSpan] =
deriveConfiguredEncoder
Encoder.forProduct12(
"trace_id",
"span_id",
"name",
"service",
"resource",
"type",
"start",
"duration",
"parent_id",
"error",
"meta",
"metrics"
)(s =>
(
s.traceId,
s.spanId,
s.name,
s.service,
s.resource,
s.`type`,
s.start,
s.duration,
s.parentId,
s.error,
s.meta,
s.metrics
)
)

implicit val decode: Decoder[SubmittableSpan] =
deriveConfiguredDecoder
Decoder.forProduct12(
"trace_id",
"span_id",
"name",
"service",
"resource",
"type",
"start",
"duration",
"parent_id",
"error",
"meta",
"metrics"
)(SubmittableSpan.apply)

/**
* It is very difficult to find any docs on this other than this fun Github issue by fommil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ object TracedClient {
span <- Kleisli.ask[F, Span[F]]
headers <- trace(span.kernel.map(_.toHeaders.toSeq))
withHeader = req.putHeaders(headers.map(keyValuesToRaw): _*).mapK(dropTracing(span))
reqTags <- trace(config.request.value.run(req.mapK(dropTracing(span))))
_ <- trace(span.put(reqTags.toSeq: _*))
(resp, rel) <- client.run(withHeader).mapK(trace[F]).map(_.mapK(trace[F])).allocated
respTags <- trace(config.response.value.run(resp.mapK(dropTracing(span))))
_ <- trace(span.put(respTags.toSeq: _*))
reqTags <- trace(config.request.value.run(req.mapK(dropTracing(span))))
_ <- trace(span.put(reqTags.toSeq: _*))
resTuple <- client.run(withHeader).mapK(trace[F]).map(_.mapK(trace[F])).allocated
(resp, rel) = resTuple
respTags <- trace(config.response.value.run(resp.mapK(dropTracing(span))))
_ <- trace(span.put(respTags.toSeq: _*))
} yield resp -> rel
}
)
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.5.5
sbt.version=1.6.2
Loading

0 comments on commit 7447f37

Please sign in to comment.