diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-05-31 18:10:15 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-05-31 18:10:15 -0300 |
commit | e88fa503bbe043c0e152290bbd4e68601ab79eb8 (patch) | |
tree | 1b28c3d68a874789fcc863e0daf1b52abe6dc0b8 /src/main/scala | |
parent | 148827486f116c4196888022f04ad053f4fb6e99 (diff) | |
download | Kamon-e88fa503bbe043c0e152290bbd4e68601ab79eb8.tar.gz Kamon-e88fa503bbe043c0e152290bbd4e68601ab79eb8.tar.bz2 Kamon-e88fa503bbe043c0e152290bbd4e68601ab79eb8.zip |
wip
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/akka/instrumentation/ActorRefTellInstrumentation.scala | 2 | ||||
-rw-r--r-- | src/main/scala/kamon/Kamon.scala | 10 | ||||
-rw-r--r-- | src/main/scala/kamon/executor/eventbus.scala | 30 |
3 files changed, 16 insertions, 26 deletions
diff --git a/src/main/scala/akka/instrumentation/ActorRefTellInstrumentation.scala b/src/main/scala/akka/instrumentation/ActorRefTellInstrumentation.scala index 00e4e066..f631b79a 100644 --- a/src/main/scala/akka/instrumentation/ActorRefTellInstrumentation.scala +++ b/src/main/scala/akka/instrumentation/ActorRefTellInstrumentation.scala @@ -20,7 +20,7 @@ class ActorRefTellInstrumentation { def around(pjp: ProceedingJoinPoint, message: Any, sender: ActorRef): Unit = { import pjp._ - Kamon.context match { + Kamon.context() match { case Some(ctx) => { val traceableMessage = TraceableMessage(ctx, message) proceed(getArgs.updated(0, traceableMessage)) diff --git a/src/main/scala/kamon/Kamon.scala b/src/main/scala/kamon/Kamon.scala index b5998f81..4cba2342 100644 --- a/src/main/scala/kamon/Kamon.scala +++ b/src/main/scala/kamon/Kamon.scala @@ -6,15 +6,19 @@ object Kamon { implicit val actorSystem = ActorSystem("kamon") - private val ctx = new ThreadLocal[Option[TraceContext]] { + val ctx = new ThreadLocal[Option[TraceContext]] { override def initialValue() = None } - def context = ctx.get() + def context() = ctx.get() def clear = ctx.remove() def set(traceContext: TraceContext) = ctx.set(Some(traceContext)) - def start: Unit = set(newTraceContext) + def start = set(newTraceContext) + def stop = ctx.get match { + case Some(context) => context.close + case None => + } def newTraceContext(): TraceContext = TraceContext() diff --git a/src/main/scala/kamon/executor/eventbus.scala b/src/main/scala/kamon/executor/eventbus.scala index d83f2ac6..ed76334f 100644 --- a/src/main/scala/kamon/executor/eventbus.scala +++ b/src/main/scala/kamon/executor/eventbus.scala @@ -5,7 +5,7 @@ import akka.event.LookupClassification import akka.actor._ import java.util.concurrent.TimeUnit -import kamon.{Kamon, TraceContext} +import kamon.{CodeBlockExecutionTime, Kamon, TraceContext} import akka.util.Timeout import scala.util.Success import scala.util.Failure @@ -88,34 +88,20 @@ object TryAkka extends App{ import akka.pattern.ask implicit val timeout = Timeout(10, TimeUnit.SECONDS) implicit def execContext = system.dispatcher - //for(i <- 1 to 8) { -/* val i = 1 - TraceContext.start - val ping = system.actorOf(Props(new PingActor(system.actorOf(Props[PongActor], s"ping-${i}"))), s"pong-${i}") - val f = ping ? Pong() - - f.map({ - a => threadPrintln(s"In the map body, with the context: ${TraceContext.current}") - }) - .flatMap({ - (a: Any) => { - threadPrintln(s"Executing the flatMap, with the context: ${TraceContext.current}") - Future { s"In the flatMap body, with the context: ${TraceContext.current}" } - } - }) - .onComplete({ - case Success(p) => threadPrintln(s"On my main success, with String [$p] and the context: ${TraceContext.current}") - case Failure(t) => threadPrintln(s"Something went wrong in the main, with the context: ${TraceContext.current}") - })*/ - //} + + Kamon.start + + Kamon.context.get.append(CodeBlockExecutionTime("some-block", System.nanoTime(), System.nanoTime())) threadPrintln("Before doing it") val f = Future { threadPrintln("This is happening inside the future body") } - Kamon.context.get.close + Kamon.stop + Thread.sleep(3000) + system.shutdown() /* appActorEventBus.subscribe(subscriber, NEW_POST_CHANNEL) appActorEventBus.publish(MessageEvent(NEW_POST_CHANNEL,PostMessage(text="hello world")))*/ |