@@ -2,20 +2,18 @@ package com.colisweb.tracing.context
2
2
3
3
import cats .data .OptionT
4
4
import cats .effect ._
5
- import cats .effect .concurrent .Ref
5
+ import cats .effect .kernel .Ref
6
6
import cats .syntax .all ._
7
7
import com .colisweb .tracing .core ._
8
8
import com .typesafe .scalalogging .StrictLogging
9
9
import org .slf4j .Logger
10
10
11
- import scala .concurrent .duration .MILLISECONDS
12
-
13
11
/** A tracing context that will log the beginning and the end of all traces along with
14
12
* their tags.
15
13
* The traces will be emitted with a TRACE level, so make sure to configure your logging backend
16
14
* to ennable the TRACE level for com.colisweb.tracing
17
15
*/
18
- class LoggingTracingContext [F [_]: Sync : Timer ](
16
+ class LoggingTracingContext [F [_]: Sync ](
19
17
traceIdP : String ,
20
18
spanIdP : String ,
21
19
tagsRef : Ref [F , Tags ],
@@ -41,7 +39,7 @@ object LoggingTracingContext extends StrictLogging {
41
39
/** Returns a Resource[F, TracingContext[F]]. The first log will be emitted
42
40
* as the resource is acquired, the second log when it is released.
43
41
*/
44
- def apply [F [_]: Sync : Timer ](
42
+ def apply [F [_]: Sync ](
45
43
parentContext : Option [LoggingTracingContext [F ]] = None ,
46
44
idGenerator : Option [F [String ]] = None ,
47
45
slf4jLogger : org.slf4j.Logger = logger.underlying,
@@ -52,7 +50,7 @@ object LoggingTracingContext extends StrictLogging {
52
50
): TracingContextResource [F ] =
53
51
resource(parentContext, idGenerator, slf4jLogger, operationName, correlationId).evalMap(ctx => ctx.addTags(tags).map(_ => ctx))
54
52
55
- private def resource [F [_]: Sync : Timer ](
53
+ private def resource [F [_]: Sync ](
56
54
parentContext : Option [LoggingTracingContext [F ]],
57
55
idGenerator : Option [F [String ]],
58
56
slf4jLogger : org.slf4j.Logger ,
@@ -68,7 +66,7 @@ object LoggingTracingContext extends StrictLogging {
68
66
tagsRef <- Ref [F ].of[Tags ](Map .empty)
69
67
spanId <- idGeneratorValue
70
68
traceId <- traceIdF
71
- start <- Clock [F ].monotonic( MILLISECONDS )
69
+ start <- Clock [F ].monotonic.map(_.toMillis )
72
70
ctx = new LoggingTracingContext [F ](traceId, spanId, tagsRef, correlationId)
73
71
details = SpanDetails (start, traceId, spanId, ctx, tagsRef)
74
72
_ <- logger.trace(" Trace {} Starting Span {} ({})" , traceId, spanId, operationName)
@@ -78,7 +76,7 @@ object LoggingTracingContext extends StrictLogging {
78
76
case SpanDetails (start, traceId, spanId, _, tagsRef) =>
79
77
for {
80
78
tags <- tagsRef.get
81
- end <- Clock [F ].monotonic( MILLISECONDS )
79
+ end <- Clock [F ].monotonic.map(_.toMillis )
82
80
duration = end - start
83
81
_ <- logger.trace(
84
82
" Trace {} Finished Span {} ({}) in {}ms. Tags: {}" ,
@@ -109,7 +107,7 @@ object LoggingTracingContext extends StrictLogging {
109
107
* This is provided for convenience and consistency with regards to the other
110
108
* tracing contexts types.
111
109
*/
112
- def builder [F [_]: Sync : Timer ]: F [TracingContextBuilder [F ]] =
110
+ def builder [F [_]: Sync ]: F [TracingContextBuilder [F ]] =
113
111
Sync [F ].delay((operationName : String , tags : Tags , correlationId : String ) =>
114
112
LoggingTracingContext .apply(correlationId = correlationId)(operationName, tags)
115
113
)
0 commit comments