blob: 246614451844d5bda30b02df47ad9e360f08f985 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package kamon
/**
* Provides support for making a TraceContext available as ThreadLocal and cleanning up afterwards.
*/
trait TraceContextSwap {
def withContext[A](ctx: Option[TraceContext], body: => A): A = withContext(ctx, body, body)
def withContext[A](ctx: Option[TraceContext], primary: => A, fallback: => A): A = {
ctx match {
case Some(context) => {
Tracer.set(context)
val bodyResult = primary
Tracer.clear
bodyResult
}
case None => fallback
}
}
}
object TraceContextSwap extends TraceContextSwap
|