Skip to content

Commit

Permalink
Merge pull request #31 from tpolecat/topic/upgrade-natchez
Browse files Browse the repository at this point in the history
Upgrade to natchez 0.3.0
  • Loading branch information
mpilquist authored Jan 17, 2023
2 parents f7b0b30 + b41906a commit c23b5ac
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 52 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v1
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.sbt
Expand All @@ -70,7 +70,7 @@ jobs:
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'temurin@17'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: scalaJSLink
Expand All @@ -85,11 +85,11 @@ jobs:
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@17'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@17'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
Expand All @@ -102,7 +102,7 @@ jobs:

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
path: targets.tar
Expand All @@ -119,28 +119,28 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Java (temurin@17)
id: download-java-temurin-17
if: matrix.java == 'temurin@17'
uses: typelevel/download-java@v1
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 17

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.sbt
Expand All @@ -152,7 +152,7 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.17, rootJS)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJS

Expand All @@ -162,7 +162,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.12.17, rootJVM)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJVM

Expand All @@ -172,7 +172,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.12.17, rootNative)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootNative

Expand All @@ -182,7 +182,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13.10, rootJS)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJS

Expand All @@ -192,7 +192,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13.10, rootJVM)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJVM

Expand All @@ -202,7 +202,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13.10, rootNative)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootNative

Expand All @@ -212,7 +212,7 @@ jobs:
rm targets.tar
- name: Download target directories (3.2.1, rootJS)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJS

Expand All @@ -222,7 +222,7 @@ jobs:
rm targets.tar
- name: Download target directories (3.2.1, rootJVM)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJVM

Expand All @@ -232,7 +232,7 @@ jobs:
rm targets.tar
- name: Download target directories (3.2.1, rootNative)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootNative

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ThisBuild / tlBaseVersion := "0.5"

val http4sVersion = "0.23.17"
val natchezVersion = "0.3.0-M3"
val natchezVersion = "0.3.0"
val scala212Version = "2.12.17"
val scala213Version = "2.13.10"
val scala3Version = "3.2.1"
Expand Down
66 changes: 42 additions & 24 deletions modules/http4s/src/test/scala/natchez/http4s/InMemory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package http4s
import java.net.URI

import cats.data.{Chain, Kleisli}
import cats.effect.{IO, Ref, Resource}
import cats.effect.{IO, MonadCancelThrow, Ref, Resource}

import natchez.Span.Options
import munit.CatsEffectSuite
Expand All @@ -19,14 +19,16 @@ object InMemory {
lineage: Lineage,
k: Kernel,
ref: Ref[IO, Chain[(Lineage, NatchezCommand)]],
val spanCreationPolicy: Options.SpanCreationPolicy
val options: Options
) extends natchez.Span.Default[IO] {
override protected val spanCreationPolicyOverride: Options.SpanCreationPolicy =
options.spanCreationPolicy

def put(fields: (String, natchez.TraceValue)*): IO[Unit] =
ref.update(_.append(lineage -> NatchezCommand.Put(fields.toList)))

def attachError(err: Throwable): IO[Unit] =
ref.update(_.append(lineage -> NatchezCommand.AttachError(err)))
def attachError(err: Throwable, fields: (String, TraceValue)*): IO[Unit] =
ref.update(_.append(lineage -> NatchezCommand.AttachError(err, fields.toList)))

def log(event: String): IO[Unit] =
ref.update(_.append(lineage -> NatchezCommand.LogEvent(event)))
Expand All @@ -39,8 +41,8 @@ object InMemory {

def makeSpan(name: String, options: Options): Resource[IO, natchez.Span[IO]] = {
val acquire = ref
.update(_.append(lineage -> NatchezCommand.CreateSpan(name, options.parentKernel)))
.as(new Span(lineage / name, k, ref, options.spanCreationPolicy))
.update(_.append(lineage -> NatchezCommand.CreateSpan(name, options.parentKernel, options)))
.as(new Span(lineage / name, k, ref, options))

val release = ref.update(_.append(lineage -> NatchezCommand.ReleaseSpan(name)))

Expand All @@ -60,19 +62,31 @@ object InMemory {
class EntryPoint(val ref: Ref[IO, Chain[(Lineage, NatchezCommand)]])
extends natchez.EntryPoint[IO] {

def root(name: String): Resource[IO, Span] =
newSpan(name, Kernel(Map.empty))

def continue(name: String, kernel: Kernel): Resource[IO, Span] =
newSpan(name, kernel)

def continueOrElseRoot(name: String, kernel: Kernel): Resource[IO, Span] =
newSpan(name, kernel)

private def newSpan(name: String, kernel: Kernel): Resource[IO, Span] = {
override def root(name: String, options: natchez.Span.Options): Resource[IO, Span] =
newSpan(name, Kernel(Map.empty), options)

override def continue(
name: String,
kernel: Kernel,
options: natchez.Span.Options
): Resource[IO, Span] =
newSpan(name, kernel, options)

override def continueOrElseRoot(
name: String,
kernel: Kernel,
options: natchez.Span.Options
): Resource[IO, Span] =
newSpan(name, kernel, options)

private def newSpan(
name: String,
kernel: Kernel,
options: natchez.Span.Options
): Resource[IO, Span] = {
val acquire = ref
.update(_.append(Lineage.Root -> NatchezCommand.CreateRootSpan(name, kernel)))
.as(new Span(Lineage.Root, kernel, ref, Options.SpanCreationPolicy.Default))
.update(_.append(Lineage.Root -> NatchezCommand.CreateRootSpan(name, kernel, options)))
.as(new Span(Lineage.Root, kernel, ref, options))

val release = ref.update(_.append(Lineage.Root -> NatchezCommand.ReleaseRootSpan(name)))

Expand Down Expand Up @@ -100,13 +114,16 @@ object InMemory {
case object AskTraceId extends NatchezCommand
case object AskTraceUri extends NatchezCommand
case class Put(fields: List[(String, natchez.TraceValue)]) extends NatchezCommand
case class CreateSpan(name: String, kernel: Option[Kernel]) extends NatchezCommand
case class CreateSpan(name: String, kernel: Option[Kernel], options: natchez.Span.Options)
extends NatchezCommand
case class ReleaseSpan(name: String) extends NatchezCommand
case class AttachError(err: Throwable) extends NatchezCommand
case class AttachError(err: Throwable, fields: List[(String, TraceValue)])
extends NatchezCommand
case class LogEvent(event: String) extends NatchezCommand
case class LogFields(fields: List[(String, TraceValue)]) extends NatchezCommand
// entry point
case class CreateRootSpan(name: String, kernel: Kernel) extends NatchezCommand
case class CreateRootSpan(name: String, kernel: Kernel, options: natchez.Span.Options)
extends NatchezCommand
case class ReleaseRootSpan(name: String) extends NatchezCommand
}

Expand All @@ -119,15 +136,15 @@ trait InMemorySuite extends CatsEffectSuite {
val NatchezCommand = InMemory.NatchezCommand

trait TraceTest {
def program[F[_]: Trace]: F[Unit]
def program[F[_]: MonadCancelThrow: Trace]: F[Unit]
def expectedHistory: List[(Lineage, NatchezCommand)]
}

def traceTest(name: String, tt: TraceTest) = {
test(s"$name - Kleisli")(
testTraceKleisli(tt.program[Kleisli[IO, Span[IO], *]](_), tt.expectedHistory)
testTraceKleisli(tt.program[Kleisli[IO, Span[IO], *]](implicitly, _), tt.expectedHistory)
)
test(s"$name - IOLocal")(testTraceIoLocal(tt.program[IO](_), tt.expectedHistory))
test(s"$name - IOLocal")(testTraceIoLocal(tt.program[IO](implicitly, _), tt.expectedHistory))
}

def testTraceKleisli(
Expand Down Expand Up @@ -160,3 +177,4 @@ trait InMemorySuite extends CatsEffectSuite {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package natchez.http4s
import cats.Monad
import cats.data.{ Chain, Kleisli }
import cats.effect.{ IO, MonadCancelThrow, Resource }
import natchez.{Kernel, Trace}
import natchez.{Kernel, Span, Trace}
import natchez.TraceValue.StringValue
import natchez.http4s.syntax.entrypoint._
import org.http4s._
Expand Down Expand Up @@ -96,9 +96,9 @@ class NatchezMiddlewareSuite extends InMemorySuite {
)

List(
(Lineage.Root, NatchezCommand.CreateRootSpan("/hello/some-name", requestKernel)),
(Lineage.Root, NatchezCommand.CreateSpan("call-proxy", None)),
(Lineage.Root / "call-proxy", NatchezCommand.CreateSpan("http4s-client-request", None)),
(Lineage.Root, NatchezCommand.CreateRootSpan("/hello/some-name", requestKernel, Span.Options.Defaults)),
(Lineage.Root, NatchezCommand.CreateSpan("call-proxy", None, Span.Options.Defaults)),
(Lineage.Root / "call-proxy", NatchezCommand.CreateSpan("http4s-client-request", None, Span.Options.Defaults)),
(Lineage.Root / "call-proxy" / "http4s-client-request", NatchezCommand.AskKernel(requestKernel)),
(Lineage.Root / "call-proxy" / "http4s-client-request", NatchezCommand.Put(clientRequestTags)),
(Lineage.Root / "call-proxy" / "http4s-client-request", NatchezCommand.Put(clientResponseTags)),
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.8.0
sbt.version=1.8.2
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.17")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.18")
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.10.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
Expand Down

0 comments on commit c23b5ac

Please sign in to comment.