aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala
diff options
context:
space:
mode:
authorIvan Topolnak <ivantopo@gmail.com>2013-08-07 19:06:33 -0300
committerIvan Topolnak <ivantopo@gmail.com>2013-08-07 19:06:33 -0300
commitcd1a9dd25fb550a515e7a7408b88233773268c38 (patch)
tree98c16e292c533cc9aa51bb0f073864b1f9e2b68a /kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala
parent6566e1c41510e54dd987d3e34e40f1031169d592 (diff)
downloadKamon-cd1a9dd25fb550a515e7a7408b88233773268c38.tar.gz
Kamon-cd1a9dd25fb550a515e7a7408b88233773268c38.tar.bz2
Kamon-cd1a9dd25fb550a515e7a7408b88233773268c38.zip
upgrading to akka 2.2
Diffstat (limited to 'kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala')
-rw-r--r--kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala61
1 files changed, 61 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala
new file mode 100644
index 00000000..e75a638f
--- /dev/null
+++ b/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala
@@ -0,0 +1,61 @@
+package kamon.instrumentation
+
+import org.aspectj.lang.annotation._
+import kamon.{Kamon, TraceContext}
+import org.aspectj.lang.ProceedingJoinPoint
+import scala.Some
+
+/**
+ * Marker interface, just to make sure we don't instrument all the Runnables in the classpath.
+ */
+trait TraceContextAwareRunnable extends Runnable {}
+
+
+@Aspect("perthis(instrumentedRunnableCreation())")
+class RunnableInstrumentation {
+
+ /**
+ * 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: TraceContextAwareRunnable = null
+
+
+ /**
+ * Pointcuts
+ */
+
+ @Pointcut("execution(kamon.instrumentation.TraceContextAwareRunnable+.new(..))")
+ def instrumentedRunnableCreation(): Unit = {}
+
+ @Pointcut("execution(* kamon.instrumentation.TraceContextAwareRunnable.run())")
+ def runnableExecution() = {}
+
+
+ /**
+ * Aspect members
+ */
+
+ private val traceContext = Kamon.context
+
+
+ /**
+ * Advices
+ */
+ import kamon.TraceContextSwap.withContext
+
+ @Before("instrumentedRunnableCreation()")
+ def beforeCreation = {
+ //println((new Throwable).getStackTraceString)
+ }
+
+
+ @Around("runnableExecution()")
+ def around(pjp: ProceedingJoinPoint) = {
+ import pjp._
+
+ withContext(traceContext, proceed())
+ }
+
+}