Skip to content

Commit 8738d9e

Browse files
committed
Fixes Colisweb#9 Upgrade to cats effect 3
1 parent 5ef98c4 commit 8738d9e

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

context/src/main/scala/com/colisweb/tracing/context/LoggingTracingContext.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ package com.colisweb.tracing.context
22

33
import cats.data.OptionT
44
import cats.effect._
5-
import cats.effect.concurrent.Ref
5+
import cats.effect.kernel.Ref
66
import cats.syntax.all._
77
import com.colisweb.tracing.core._
88
import com.typesafe.scalalogging.StrictLogging
99
import org.slf4j.Logger
1010

11-
import scala.concurrent.duration.MILLISECONDS
12-
1311
/** A tracing context that will log the beginning and the end of all traces along with
1412
* their tags.
1513
* The traces will be emitted with a TRACE level, so make sure to configure your logging backend
1614
* to ennable the TRACE level for com.colisweb.tracing
1715
*/
18-
class LoggingTracingContext[F[_]: Sync: Timer](
16+
class LoggingTracingContext[F[_]: Sync](
1917
traceIdP: String,
2018
spanIdP: String,
2119
tagsRef: Ref[F, Tags],
@@ -41,7 +39,7 @@ object LoggingTracingContext extends StrictLogging {
4139
/** Returns a Resource[F, TracingContext[F]]. The first log will be emitted
4240
* as the resource is acquired, the second log when it is released.
4341
*/
44-
def apply[F[_]: Sync: Timer](
42+
def apply[F[_]: Sync](
4543
parentContext: Option[LoggingTracingContext[F]] = None,
4644
idGenerator: Option[F[String]] = None,
4745
slf4jLogger: org.slf4j.Logger = logger.underlying,
@@ -52,7 +50,7 @@ object LoggingTracingContext extends StrictLogging {
5250
): TracingContextResource[F] =
5351
resource(parentContext, idGenerator, slf4jLogger, operationName, correlationId).evalMap(ctx => ctx.addTags(tags).map(_ => ctx))
5452

55-
private def resource[F[_]: Sync: Timer](
53+
private def resource[F[_]: Sync](
5654
parentContext: Option[LoggingTracingContext[F]],
5755
idGenerator: Option[F[String]],
5856
slf4jLogger: org.slf4j.Logger,
@@ -68,7 +66,7 @@ object LoggingTracingContext extends StrictLogging {
6866
tagsRef <- Ref[F].of[Tags](Map.empty)
6967
spanId <- idGeneratorValue
7068
traceId <- traceIdF
71-
start <- Clock[F].monotonic(MILLISECONDS)
69+
start <- Clock[F].monotonic.map(_.toMillis)
7270
ctx = new LoggingTracingContext[F](traceId, spanId, tagsRef, correlationId)
7371
details = SpanDetails(start, traceId, spanId, ctx, tagsRef)
7472
_ <- logger.trace("Trace {} Starting Span {} ({})", traceId, spanId, operationName)
@@ -78,7 +76,7 @@ object LoggingTracingContext extends StrictLogging {
7876
case SpanDetails(start, traceId, spanId, _, tagsRef) =>
7977
for {
8078
tags <- tagsRef.get
81-
end <- Clock[F].monotonic(MILLISECONDS)
79+
end <- Clock[F].monotonic.map(_.toMillis)
8280
duration = end - start
8381
_ <- logger.trace(
8482
"Trace {} Finished Span {} ({}) in {}ms. Tags: {}",
@@ -109,7 +107,7 @@ object LoggingTracingContext extends StrictLogging {
109107
* This is provided for convenience and consistency with regards to the other
110108
* tracing contexts types.
111109
*/
112-
def builder[F[_]: Sync: Timer]: F[TracingContextBuilder[F]] =
110+
def builder[F[_]: Sync]: F[TracingContextBuilder[F]] =
113111
Sync[F].delay((operationName: String, tags: Tags, correlationId: String) =>
114112
LoggingTracingContext.apply(correlationId = correlationId)(operationName, tags)
115113
)

http/client/src/main/scala/com/colisweb/tracing/http/client/RequestWithCorrelationIdHelper.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ trait RequestWithCorrelationIdHelper {
2323

2424
}
2525

26-
}
26+
}

http/server/src/main/scala/com/colisweb/tracing/http/server/TracedRoutes.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ trait TracedRoutes {
1414

1515
implicit class TracedEndpoint[In, Err, Out](e: Endpoint[In, Err, Out, Any]) {
1616

17-
def toTracedRoute[F[_]: Sync: Concurrent: Timer](logic: (In, TracingContext[F]) => F[Either[Err, Out]])(implicit
17+
def toTracedRoute[F[_]: Sync](logic: (In, TracingContext[F]) => F[Either[Err, Out]])(implicit
1818
builder: TracingContextBuilder[F],
19-
cs: ContextShift[F],
2019
serverOptions: Http4sServerOptions[F]
2120
): HttpRoutes[F] = {
2221

@@ -37,10 +36,9 @@ trait TracedRoutes {
3736
implicit class TracedEndpointRecoverErrors[In, Err <: Throwable, Out](
3837
e: Endpoint[In, Err, Out, Any]
3938
) {
40-
def toTracedRouteRecoverErrors[F[_]: Sync: Concurrent: Timer](logic: (In, TracingContext[F]) => F[Out])(implicit
39+
def toTracedRouteRecoverErrors[F[_]: Sync](logic: (In, TracingContext[F]) => F[Out])(implicit
4140
builder: TracingContextBuilder[F],
4241
eClassTag: ClassTag[Err],
43-
cs: ContextShift[F],
4442
serverOptions: Http4sServerOptions[F]
4543
): HttpRoutes[F] =
4644
TracedHttpRoutes.wrapHttpRoutes(

http/server/src/test/scala/com/colisweb/tracing/http/server/TapirSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import sttp.tapir.generic.auto._
1717
import scala.concurrent.ExecutionContext
1818

1919
class TapirSpec extends AsyncFunSpec with Matchers {
20-
implicit val timer : Timer[IO] = IO.timer(ExecutionContext.global)
20+
implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
2121
import TapirSpec._
2222

2323
describe("Tapir Integration") {

project/CompileTimeDependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sbt._
33
object Versions {
44

55
final val cats = "2.4.2"
6-
final val catsEffect = "2.3.3"
6+
final val catsEffect = "3.0.0-RC2"
77
final val circe = "0.13.0"
88
final val datadog = "0.68.0"
99
final val fs2 = "3.0.1"

0 commit comments

Comments
 (0)