aboutsummaryrefslogtreecommitdiff
path: root/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2013-11-23 21:30:34 -0300
committerIvan Topolnjak <ivantopo@gmail.com>2013-11-23 21:30:34 -0300
commit6ba7487204e0339437c7279e6330fc03419a2c5c (patch)
treeeda414d575a20d4000d04f3f06207b6843919ca7 /kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala
parent741ac431e7b156c782f5f02a29a17686912cb590 (diff)
downloadKamon-6ba7487204e0339437c7279e6330fc03419a2c5c.tar.gz
Kamon-6ba7487204e0339437c7279e6330fc03419a2c5c.tar.bz2
Kamon-6ba7487204e0339437c7279e6330fc03419a2c5c.zip
Put FutureTracing instrumentation in place, simpler and more explicit test
Diffstat (limited to 'kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala')
-rw-r--r--kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala40
1 files changed, 40 insertions, 0 deletions
diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala
new file mode 100644
index 00000000..10daa2da
--- /dev/null
+++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala
@@ -0,0 +1,40 @@
+package kamon.trace.instrumentation
+
+import org.aspectj.lang.annotation._
+import org.aspectj.lang.ProceedingJoinPoint
+import kamon.trace.{ContextAware, TraceContext, Trace}
+
+@Aspect
+class FutureTracing {
+
+ /**
+ * 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
+
+
+ @Pointcut("execution(kamon.trace.ContextAware+.new(..)) && this(runnable)")
+ def instrumentedRunnableCreation(runnable: ContextAware): Unit = {}
+
+ @Pointcut("execution(* kamon.trace.ContextAware+.run()) && this(runnable)")
+ def futureRunnableExecution(runnable: ContextAware) = {}
+
+
+ @After("instrumentedRunnableCreation(runnable)")
+ def beforeCreation(runnable: ContextAware): Unit = {
+ // Force traceContext initialization.
+ runnable.traceContext
+ }
+
+ @Around("futureRunnableExecution(runnable)")
+ def around(pjp: ProceedingJoinPoint, runnable: ContextAware): Any = {
+ import pjp._
+
+ Trace.withValue(runnable.traceContext) {
+ proceed()
+ }
+ }
+
+} \ No newline at end of file