From 03c6a7d81e38dfa856ede9a188467b2c01bfb5f1 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Wed, 2 Oct 2013 09:03:42 -0300 Subject: wip --- kamon-core/src/main/scala/kamon/TraceContext.scala | 5 ++-- .../instrumentation/RunnableInstrumentation.scala | 4 ++-- .../SprayServerInstrumentation.scala | 22 +++++++++++++---- kamon-core/src/main/scala/test/PingPong.scala | 28 ++++++++++++---------- .../RunnableInstrumentationSpec.scala | 4 ++-- 5 files changed, 40 insertions(+), 23 deletions(-) (limited to 'kamon-core') diff --git a/kamon-core/src/main/scala/kamon/TraceContext.scala b/kamon-core/src/main/scala/kamon/TraceContext.scala index 4ad533fd..0dfc1630 100644 --- a/kamon-core/src/main/scala/kamon/TraceContext.scala +++ b/kamon-core/src/main/scala/kamon/TraceContext.scala @@ -22,10 +22,11 @@ object TraceContext { val traceIdCounter = new AtomicLong def apply()(implicit system: ActorSystem) = { - val actor = system.actorOf(UowTraceAggregator.props(reporter, 5 seconds), s"tracer-${traceIdCounter.incrementAndGet()}") + val n = traceIdCounter.incrementAndGet() + val actor = system.actorOf(UowTraceAggregator.props(reporter, 5 seconds), s"tracer-${n}") actor ! Start() - new TraceContext(100, actor) // TODO: Move to a kamon specific supervisor, like /user/kamon/tracer + new TraceContext(n, actor) // TODO: Move to a kamon specific supervisor, like /user/kamon/tracer } } diff --git a/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala index 393293f1..bff118d9 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/RunnableInstrumentation.scala @@ -58,8 +58,8 @@ class RunnableInstrumentation { @Around("runnableExecution()") def around(pjp: ProceedingJoinPoint) = { import pjp._ - /*if(traceContext.isEmpty) - println("OOHHH NOOOOO")*/ + if(traceContext.isEmpty) + println("NOMONEY") withContext(traceContext, proceed()) } diff --git a/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala index 0299c4c5..06254739 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala @@ -32,20 +32,32 @@ class SprayServerInstrumentation { //@After("openRequestInit()") //def afterInit(): Unit = { Tracer.start + val discard = openRequest.asInstanceOf[ContextAware].traceContext + + //println("Reply: %s - %s ", Tracer.context().get.id, request.uri.path.toString()) + +// if(discard.isEmpty || discard != Tracer.context()) { +// println("MEGA ERROR") +// } //openRequest.traceContext //println("Created the context: " + Tracer.context() + " for the transaction: " + request) Tracer.context().map(_.entries ! Rename(request.uri.path.toString())) } - @Pointcut("execution(* spray.can.server.OpenRequestComponent$DefaultOpenRequest.handleResponseEndAndReturnNextOpenRequest(..))") - def openRequestCreation(): Unit = {} + @Pointcut("execution(* spray.can.server.OpenRequestComponent$DefaultOpenRequest.handleResponseEndAndReturnNextOpenRequest(..)) && target(openRequest)") + def openRequestCreation(openRequest: OpenRequest): Unit = {} - @After("openRequestCreation()") - def afterFinishingRequest(): Unit = { + @After("openRequestCreation(openRequest)") + def afterFinishingRequest(openRequest: OpenRequest): Unit = { // println("Finishing a request: " + Tracer.context()) - + val original = openRequest.asInstanceOf[ContextAware].traceContext + println("The original is: " + original + " - " + openRequest.request.uri.path) Tracer.context().map(_.entries ! Finish()) + if(Tracer.context() != original) { + println(s"OMG DIFFERENT Original: [${original}] - Came in: [${Tracer.context}]") + } + if(Tracer.context().isEmpty) { println("WOOOOOPAAAAAAAAA") } diff --git a/kamon-core/src/main/scala/test/PingPong.scala b/kamon-core/src/main/scala/test/PingPong.scala index 6d8c4636..8808e4bf 100644 --- a/kamon-core/src/main/scala/test/PingPong.scala +++ b/kamon-core/src/main/scala/test/PingPong.scala @@ -93,22 +93,26 @@ object SimpleRequestProcessor extends App with SimpleRoutingApp with RequestBuil } -object Verifier extends App with RequestBuilding { - import scala.concurrent.duration._ - import spray.client.pipelining._ - import akka.pattern.ask +object Verifier extends App { - implicit val system = ActorSystem("test") - import system.dispatcher + def go: Unit = { + import scala.concurrent.duration._ + import spray.client.pipelining._ + import akka.pattern.ask - implicit val timeout = Timeout(30 seconds) + implicit val system = ActorSystem("test") + import system.dispatcher - val pipeline = sendReceive + implicit val timeout = Timeout(30 seconds) + + val pipeline = sendReceive + + val futures = Future.sequence(for(i <- 1 to 500) yield { + pipeline(Get("http://127.0.0.1:9090/reply/"+i)).map(r => r.entity.asString == i.toString) + }) + println("Everything is: "+ Await.result(futures, 10 seconds).forall(a => a == true)) + } - val futures = Future.sequence(for(i <- 1 to 500) yield { - pipeline(Get("http://127.0.0.1/reply/"+i)).map(r => r.entity.asString == i.toString) - }) - Await.result(futures, 10 seconds).forall(_) diff --git a/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala index fe89695b..86bef0d8 100644 --- a/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala +++ b/kamon-core/src/test/scala/kamon/instrumentation/RunnableInstrumentationSpec.scala @@ -25,7 +25,7 @@ class RunnableInstrumentationSpec extends WordSpec with Matchers with ScalaFutur "should be available during the execution of onComplete callbacks" in { new FutureWithContextFixture { val onCompleteContext = Promise[TraceContext]() - + Tracer.clear futureWithContext.onComplete({ case _ => onCompleteContext.complete(Success(Tracer.context.get)) }) @@ -70,7 +70,7 @@ class RunnableInstrumentationSpec extends WordSpec with Matchers with ScalaFutur val testContext = TraceContext() Tracer.set(testContext) - val futureWithContext = Future { Tracer.context} + val futureWithContext = Future { Tracer.context } } trait FutureWithoutContextFixture { -- cgit v1.2.3