diff options
author | Diego Parra <diegolparra@gmail.com> | 2013-05-24 00:20:33 -0300 |
---|---|---|
committer | Diego Parra <diegolparra@gmail.com> | 2013-05-24 00:20:33 -0300 |
commit | 789b70deb75bc669354d503090d247b61deed7dc (patch) | |
tree | d96a46274d9bdbdb71ddaf538dbee3a1114418ff /src/main/scala | |
parent | a12e8579e09c5fd8fdf98ba4553f0a232ddfea6b (diff) | |
download | Kamon-789b70deb75bc669354d503090d247b61deed7dc.tar.gz Kamon-789b70deb75bc669354d503090d247b61deed7dc.tar.bz2 Kamon-789b70deb75bc669354d503090d247b61deed7dc.zip |
WIP: Instrumentation on Future.apply
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/kamon/instrumentation/PromiseInstrumentation.scala | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/main/scala/kamon/instrumentation/PromiseInstrumentation.scala b/src/main/scala/kamon/instrumentation/PromiseInstrumentation.scala index 45e9c414..087e43bf 100644 --- a/src/main/scala/kamon/instrumentation/PromiseInstrumentation.scala +++ b/src/main/scala/kamon/instrumentation/PromiseInstrumentation.scala @@ -1,10 +1,11 @@ package kamon.instrumentation -import org.aspectj.lang.annotation.{Around, Before, Pointcut, Aspect} +import org.aspectj.lang.annotation._ import kamon.TraceContext import scala.util.Try import scala.concurrent.ExecutionContext import org.aspectj.lang.ProceedingJoinPoint +import scala.Some @Aspect("perthis(promiseCreation())") class PromiseInstrumentation { @@ -43,4 +44,29 @@ class PromiseInstrumentation { proceed(getArgs.updated(0, wrappedFunction)) } + + @Pointcut("execution(* scala.concurrent.impl.Future$.apply(..)) && args(body, executor)") + def registeringApplyOnFuture(body: () => Any, executor: ExecutionContext) = {} + + @Around("registeringApplyOnFuture(body, executor)") + def aroundApplyOnFuture(pjp:ProceedingJoinPoint, body: () => Any, executor: ExecutionContext) = { + import pjp._ + + val wrappedBody = wrapFutureBody(traceContext)(body) + proceed(getArgs.updated(0, wrappedBody)) + } + + def wrapFutureBody[A](ctx:Option[TraceContext])(block: => A) : A = { + ctx match { + case Some(ctx) => { + println("Wrapping body") + TraceContext.set(ctx) + val result = block + TraceContext.clear + result + } + case None => block + } + } + } |