Skip to content

Commit

Permalink
Merge pull request #332 from tpolecat/merge-with-master
Browse files Browse the repository at this point in the history
merge with master
  • Loading branch information
tpolecat authored Apr 27, 2021
2 parents a8e63e1 + 0279a73 commit d6dfa82
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
50 changes: 27 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ lazy val commonSettings = Seq(
// Testing
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "0.7.25" % Test,
"org.typelevel" %%% "munit-cats-effect-2" % "1.0.2" % Test,
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.2" % Test,
),
testFrameworks += new TestFramework("munit.Framework"),

Expand Down Expand Up @@ -206,7 +206,7 @@ lazy val lightstepGrpc = project
libraryDependencies ++= Seq(
"com.lightstep.tracer" % "tracer-grpc" % "0.30.3",
"io.grpc" % "grpc-netty" % "1.37.0",
"io.netty" % "netty-tcnative-boringssl-static" % "2.0.38.Final"
"io.netty" % "netty-tcnative-boringssl-static" % "2.0.39.Final"
)
)

Expand Down Expand Up @@ -254,27 +254,31 @@ lazy val datadog = project
)
)

// lazy val log = crossProject(JSPlatform, JVMPlatform)
// .in(file("modules/log"))
// .enablePlugins(AutomateHeaderPlugin)
// .settings(commonSettings)
// .settings(crossProjectSettings)
// .settings(
// publish / skip := isDotty.value,
// name := "natchez-log",
// description := "Logging bindings for Natchez, using log4cats.",
// libraryDependencies ++= Seq(
// "io.circe" %%% "circe-core" % "0.13.0",
// "io.chrisdavenport" %%% "log4cats-core" % "1.1.1",
// ).filterNot(_ => isDotty.value)
// )
// lazy val logJVM = log.jvm.dependsOn(coreJVM)
// lazy val logJS = log.js.dependsOn(coreJS)
// .settings(
// scalaJSStage in Test := FastOptStage,
// jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
// scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
// )
lazy val log = crossProject(JSPlatform, JVMPlatform)
.in(file("modules/log"))
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(crossProjectSettings)
.settings(
name := "natchez-log",
description := "Logging bindings for Natchez, using log4cats.",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % {
if (scalaVersion.value == scala30PreviousVersion) "0.14.0-M5"
else if (scalaVersion.value == scala30Version) "0.14.0-M6"
else "0.13.0"
},
"org.typelevel" %%% "log4cats-core" % "2.1.0",
"io.github.cquiroz" %%% "scala-java-time" % "2.2.2" % Test,
)
)
lazy val logJVM = log.jvm.dependsOn(coreJVM)
lazy val logJS = log.js.dependsOn(coreJS)
.settings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)

lazy val newrelic = project
.in(file("modules/newrelic"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package log

import cats.effect.{ Resource, Sync }
import cats.syntax.functor._
import io.chrisdavenport.log4cats.Logger
import org.typelevel.log4cats.Logger
import io.circe.Json

object Log {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

package natchez.log

import cats.effect.concurrent.Ref
import cats.effect.Ref
import cats.effect._
import cats.effect.ExitCase._
import cats.effect.Resource.ExitCase
import cats.effect.Resource.ExitCase._
import cats.syntax.all._
import java.time.Instant
import java.util.UUID
Expand All @@ -16,7 +17,7 @@ import io.circe.Json
import io.circe.Encoder
import io.circe.syntax._
import io.circe.JsonObject
import io.chrisdavenport.log4cats.Logger
import org.typelevel.log4cats.Logger
import java.net.URI

private[log] final case class LogSpan[F[_]: Sync: Logger](
Expand Down Expand Up @@ -52,7 +53,7 @@ private[log] final case class LogSpan[F[_]: Sync: Logger](
def span(label: String): Resource[F, Span[F]] =
Span.putErrorFields(Resource.makeCase(LogSpan.child(this, label))(LogSpan.finishChild[F]).widen)

def json(finish: Instant, exitCase: ExitCase[Throwable]): F[JsonObject] =
def json(finish: Instant, exitCase: ExitCase): F[JsonObject] =
(fields.get, children.get).mapN { (fs, cs) =>

// Assemble our JSON object such that the Natchez fields always come first, in the same
Expand All @@ -77,10 +78,10 @@ private[log] final case class LogSpan[F[_]: Sync: Logger](
"trace.trace_id" -> traceUUID.asJson,
) ++ {
exitCase match {
case Completed => List("exit.case" -> "completed".asJson)
case Canceled => List("exit.case" -> "canceled".asJson)
case Error(ex: Fields) => exitFields(ex) ++ ex.fields.toList.map(_.map(_.asJson))
case Error(ex) => exitFields(ex)
case Succeeded => List("exit.case" -> "succeeded".asJson)
case Canceled => List("exit.case" -> "canceled".asJson)
case Errored(ex: Fields) => exitFields(ex) ++ ex.fields.toList.map { case (k, v) => (k, v.asJson) }
case Errored(ex) => exitFields(ex)
}
} ++ fs ++ List("children" -> cs.reverse.map(Json.fromJsonObject).asJson)

Expand All @@ -91,8 +92,8 @@ private[log] final case class LogSpan[F[_]: Sync: Logger](
def traceId: F[Option[String]] =
traceUUID.toString.some.pure[F]

def spanId: F[Option[String]] =
sid.toString.some.pure[F]
def spanId: F[Option[String]] =
sid.toString.some.pure[F]

def traceUri: F[Option[URI]] = none.pure[F]
}
Expand Down Expand Up @@ -127,7 +128,7 @@ private[log] object LogSpan {
private def now[F[_]: Sync]: F[Instant] =
Sync[F].delay(Instant.now)

def finish[F[_]: Sync: Logger](format: Json => String): (LogSpan[F], ExitCase[Throwable]) => F[Unit] = { (span, exitCase) =>
def finish[F[_]: Sync: Logger](format: Json => String): (LogSpan[F], ExitCase) => F[Unit] = { (span, exitCase) =>
for {
n <- now
j <- span.json(n, exitCase)
Expand All @@ -139,7 +140,7 @@ private[log] object LogSpan {
} yield ()
}

def finishChild[F[_]: Sync: Logger]: (LogSpan[F], ExitCase[Throwable]) => F[Unit] =
def finishChild[F[_]: Sync: Logger]: (LogSpan[F], ExitCase) => F[Unit] =
finish(_ => sys.error("implementation error; child JSON should never be logged"))

def child[F[_]: Sync: Logger](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class LogSuite extends CatsEffectSuite {
"""|test: [info] {
| "name" : "root span",
| "service" : "service",
| "exit.case" : "completed",
| "exit.case" : "succeeded",
| "foo" : 1,
| "bar" : true,
| "children" : [
| {
| "name" : "child",
| "service" : "service",
| "exit.case" : "completed",
| "exit.case" : "succeeded",
| "baz" : "qux",
| "children" : [
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package natchez
package log

import io.chrisdavenport.log4cats.Logger
import org.typelevel.log4cats.Logger
import cats.effect.Sync
import cats.effect.concurrent.Ref
import cats.effect.Ref
import cats.syntax.all._

trait MockLogger[F[_]] extends Logger[F] {
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.0
sbt.version=1.5.1

0 comments on commit d6dfa82

Please sign in to comment.