diff options
Diffstat (limited to 'kamon-core/src/main/scala/kamon/instrumentation')
-rw-r--r-- | kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala | 10 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala | 33 |
2 files changed, 39 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala index 84498cb8..4f0b8a08 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala @@ -2,13 +2,14 @@ package kamon.instrumentation import org.aspectj.lang.annotation._ import org.aspectj.lang.ProceedingJoinPoint -import akka.actor.{Props, ActorSystem, ActorRef} +import akka.actor.{ActorCell, Props, ActorSystem, ActorRef} import kamon.{Kamon, Tracer, TraceContext} import akka.dispatch.{MessageDispatcher, Envelope} import com.codahale.metrics.Timer import kamon.metric.{MetricDirectory, Metrics} import scala.Some import kamon.instrumentation.SimpleContextPassingInstrumentation.SimpleTraceMessage +import org.slf4j.MDC case class TraceableMessage(traceContext: Option[TraceContext], message: Any, timer: Timer.Context) @@ -52,11 +53,14 @@ class ActorCellInvokeInstrumentation { import ProceedingJoinPointPimp._ val (originalEnvelope, ctx) = instrumentation.preReceive(envelope) + //println("Test") ctx match { case Some(c) => { + //MDC.put("uow", c.userContext.get.asInstanceOf[String]) Tracer.set(c) pjp.proceedWith(originalEnvelope) Tracer.clear + //MDC.remove("uow") } case None => pjp.proceedWith(originalEnvelope) } @@ -74,9 +78,7 @@ class UnregisteredActorRefInstrumentation { import ProceedingJoinPointPimp._ println("Handling unregistered actor ref message: "+message) message match { - case TraceableMessage(ctx, msg, timer) => { - timer.stop() - + case SimpleTraceMessage(msg, ctx) => { ctx match { case Some(c) => { Tracer.set(c) diff --git a/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala new file mode 100644 index 00000000..6573549d --- /dev/null +++ b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala @@ -0,0 +1,33 @@ +package kamon.instrumentation + +import org.aspectj.lang.annotation.{After, Pointcut, Aspect} +import kamon.Tracer +import kamon.trace.UowTracing.{Finish, Rename} +import spray.http.HttpRequest +import spray.can.server.OpenRequestComponent + +@Aspect +class SprayServerInstrumentation { + + @Pointcut("execution(spray.can.server.OpenRequestComponent$DefaultOpenRequest.new(..)) && args(enclosing, request, closeAfterResponseCompletion, timestamp)") + def openRequestInit(enclosing: OpenRequestComponent, request: HttpRequest, closeAfterResponseCompletion: Boolean, timestamp: Long): Unit = {} + + @After("openRequestInit(enclosing, request, closeAfterResponseCompletion, timestamp)") + def afterInit(enclosing: OpenRequestComponent, request: HttpRequest, closeAfterResponseCompletion: Boolean, timestamp: Long): Unit = { + //@After("openRequestInit()") + //def afterInit(): Unit = { + Tracer.start + println("Created the context: " + Tracer.context() + " for the transaction: " + request.uri.path.toString()) + Tracer.context().map(_.entries ! Rename(request.uri.path.toString())) + } + + @Pointcut("execution(* spray.can.server.OpenRequest.handleResponseEndAndReturnNextOpenRequest(..))") + def openRequestCreation(): Unit = {} + + @After("openRequestCreation()") + def afterFinishingRequest(): Unit = { + println("Finishing a request: " + Tracer.context()) + + Tracer.context().map(_.entries ! Finish()) + } +}
\ No newline at end of file |