diff --git a/context/src/main/scala/com/colisweb/tracing/context/LoggingTracingContext.scala b/context/src/main/scala/com/colisweb/tracing/context/LoggingTracingContext.scala index 3736828d..50d68a66 100644 --- a/context/src/main/scala/com/colisweb/tracing/context/LoggingTracingContext.scala +++ b/context/src/main/scala/com/colisweb/tracing/context/LoggingTracingContext.scala @@ -2,20 +2,18 @@ package com.colisweb.tracing.context import cats.data.OptionT import cats.effect._ -import cats.effect.concurrent.Ref +import cats.effect.kernel.Ref import cats.syntax.all._ import com.colisweb.tracing.core._ import com.typesafe.scalalogging.StrictLogging import org.slf4j.Logger -import scala.concurrent.duration.MILLISECONDS - /** A tracing context that will log the beginning and the end of all traces along with * their tags. * The traces will be emitted with a TRACE level, so make sure to configure your logging backend * to ennable the TRACE level for com.colisweb.tracing */ -class LoggingTracingContext[F[_]: Sync: Timer]( +class LoggingTracingContext[F[_]: Sync]( traceIdP: String, spanIdP: String, tagsRef: Ref[F, Tags], @@ -41,7 +39,7 @@ object LoggingTracingContext extends StrictLogging { /** Returns a Resource[F, TracingContext[F]]. The first log will be emitted * as the resource is acquired, the second log when it is released. */ - def apply[F[_]: Sync: Timer]( + def apply[F[_]: Sync]( parentContext: Option[LoggingTracingContext[F]] = None, idGenerator: Option[F[String]] = None, slf4jLogger: org.slf4j.Logger = logger.underlying, @@ -52,7 +50,7 @@ object LoggingTracingContext extends StrictLogging { ): TracingContextResource[F] = resource(parentContext, idGenerator, slf4jLogger, operationName, correlationId).evalMap(ctx => ctx.addTags(tags).map(_ => ctx)) - private def resource[F[_]: Sync: Timer]( + private def resource[F[_]: Sync]( parentContext: Option[LoggingTracingContext[F]], idGenerator: Option[F[String]], slf4jLogger: org.slf4j.Logger, @@ -68,7 +66,7 @@ object LoggingTracingContext extends StrictLogging { tagsRef <- Ref[F].of[Tags](Map.empty) spanId <- idGeneratorValue traceId <- traceIdF - start <- Clock[F].monotonic(MILLISECONDS) + start <- Clock[F].monotonic.map(_.toMillis) ctx = new LoggingTracingContext[F](traceId, spanId, tagsRef, correlationId) details = SpanDetails(start, traceId, spanId, ctx, tagsRef) _ <- logger.trace("Trace {} Starting Span {} ({})", traceId, spanId, operationName) @@ -78,7 +76,7 @@ object LoggingTracingContext extends StrictLogging { case SpanDetails(start, traceId, spanId, _, tagsRef) => for { tags <- tagsRef.get - end <- Clock[F].monotonic(MILLISECONDS) + end <- Clock[F].monotonic.map(_.toMillis) duration = end - start _ <- logger.trace( "Trace {} Finished Span {} ({}) in {}ms. Tags: {}", @@ -109,7 +107,7 @@ object LoggingTracingContext extends StrictLogging { * This is provided for convenience and consistency with regards to the other * tracing contexts types. */ - def builder[F[_]: Sync: Timer]: F[TracingContextBuilder[F]] = + def builder[F[_]: Sync]: F[TracingContextBuilder[F]] = Sync[F].delay((operationName: String, tags: Tags, correlationId: String) => LoggingTracingContext.apply(correlationId = correlationId)(operationName, tags) ) diff --git a/http/client/src/main/scala/com/colisweb/tracing/http/client/RequestWithCorrelationIdHelper.scala b/http/client/src/main/scala/com/colisweb/tracing/http/client/RequestWithCorrelationIdHelper.scala index f2b56e5b..58b8472c 100644 --- a/http/client/src/main/scala/com/colisweb/tracing/http/client/RequestWithCorrelationIdHelper.scala +++ b/http/client/src/main/scala/com/colisweb/tracing/http/client/RequestWithCorrelationIdHelper.scala @@ -23,4 +23,4 @@ trait RequestWithCorrelationIdHelper { } -} \ No newline at end of file +} diff --git a/http/server/src/main/scala/com/colisweb/tracing/http/server/TracedRoutes.scala b/http/server/src/main/scala/com/colisweb/tracing/http/server/TracedRoutes.scala index 4c40b2b5..496c1188 100644 --- a/http/server/src/main/scala/com/colisweb/tracing/http/server/TracedRoutes.scala +++ b/http/server/src/main/scala/com/colisweb/tracing/http/server/TracedRoutes.scala @@ -14,9 +14,8 @@ trait TracedRoutes { implicit class TracedEndpoint[In, Err, Out](e: Endpoint[In, Err, Out, Any]) { - def toTracedRoute[F[_]: Sync: Concurrent: Timer](logic: (In, TracingContext[F]) => F[Either[Err, Out]])(implicit + def toTracedRoute[F[_]: Sync](logic: (In, TracingContext[F]) => F[Either[Err, Out]])(implicit builder: TracingContextBuilder[F], - cs: ContextShift[F], serverOptions: Http4sServerOptions[F] ): HttpRoutes[F] = { @@ -37,10 +36,9 @@ trait TracedRoutes { implicit class TracedEndpointRecoverErrors[In, Err <: Throwable, Out]( e: Endpoint[In, Err, Out, Any] ) { - def toTracedRouteRecoverErrors[F[_]: Sync: Concurrent: Timer](logic: (In, TracingContext[F]) => F[Out])(implicit + def toTracedRouteRecoverErrors[F[_]: Sync](logic: (In, TracingContext[F]) => F[Out])(implicit builder: TracingContextBuilder[F], eClassTag: ClassTag[Err], - cs: ContextShift[F], serverOptions: Http4sServerOptions[F] ): HttpRoutes[F] = TracedHttpRoutes.wrapHttpRoutes( diff --git a/http/server/src/test/scala/com/colisweb/tracing/http/server/TapirSpec.scala b/http/server/src/test/scala/com/colisweb/tracing/http/server/TapirSpec.scala index 5e6c0deb..83ff7dba 100644 --- a/http/server/src/test/scala/com/colisweb/tracing/http/server/TapirSpec.scala +++ b/http/server/src/test/scala/com/colisweb/tracing/http/server/TapirSpec.scala @@ -17,7 +17,7 @@ import sttp.tapir.generic.auto._ import scala.concurrent.ExecutionContext class TapirSpec extends AsyncFunSpec with Matchers { - implicit val timer : Timer[IO] = IO.timer(ExecutionContext.global) + implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global) import TapirSpec._ describe("Tapir Integration") { diff --git a/project/CompileTimeDependencies.scala b/project/CompileTimeDependencies.scala index d3b16caa..5f4108be 100644 --- a/project/CompileTimeDependencies.scala +++ b/project/CompileTimeDependencies.scala @@ -3,7 +3,7 @@ import sbt._ object Versions { final val cats = "2.4.2" - final val catsEffect = "2.3.3" + final val catsEffect = "3.0.0-RC2" final val circe = "0.13.0" final val datadog = "0.68.0" final val fs2 = "3.0.1"