blob: 5c16a6485a4c1b70569b9beb3aea28a2117ef115 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package kamon.trace.instrumentation
import org.aspectj.lang.annotation._
import org.aspectj.lang.ProceedingJoinPoint
import kamon.trace.{ContextAware, TraceContext, Trace}
@Aspect
class RunnableTracing {
/**
* These are the Runnables that need to be instrumented and make the TraceContext available
* while their run method is executed.
*/
@DeclareMixin("scala.concurrent.impl.CallbackRunnable || scala.concurrent.impl.Future.PromiseCompletingRunnable")
def onCompleteCallbacksRunnable: ContextAware = ContextAware.default
/**
* Pointcuts
*/
@Pointcut("execution(kamon.trace.ContextAware+.new(..)) && this(runnable)")
def instrumentedRunnableCreation(runnable: ContextAware): Unit = {}
@Pointcut("execution(* kamon.trace.ContextAware+.run()) && this(runnable)")
def runnableExecution(runnable: ContextAware) = {}
@After("instrumentedRunnableCreation(runnable)")
def beforeCreation(runnable: ContextAware): Unit = {
// Force traceContext initialization.
runnable.traceContext
}
@Around("runnableExecution(runnable)")
def around(pjp: ProceedingJoinPoint, runnable: ContextAware): Any = {
import pjp._
Trace.traceContext.withValue(runnable.traceContext) {
proceed()
}
}
}
|