diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-09-21 22:57:43 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-09-21 22:57:43 -0300 |
commit | 7a86ca357a11caa6abc89c325be8d50dd91071a6 (patch) | |
tree | 72ee968822f33686a964e132c367d821454c60e6 /kamon-core/src | |
parent | 5168621c256d25d388fb990a5bbc080a35e07b46 (diff) | |
download | Kamon-7a86ca357a11caa6abc89c325be8d50dd91071a6.tar.gz Kamon-7a86ca357a11caa6abc89c325be8d50dd91071a6.tar.bz2 Kamon-7a86ca357a11caa6abc89c325be8d50dd91071a6.zip |
wip
Diffstat (limited to 'kamon-core/src')
7 files changed, 94 insertions, 12 deletions
diff --git a/kamon-core/src/main/resources/META-INF/aop.xml b/kamon-core/src/main/resources/META-INF/aop.xml index 10110300..4705c1f2 100644 --- a/kamon-core/src/main/resources/META-INF/aop.xml +++ b/kamon-core/src/main/resources/META-INF/aop.xml @@ -20,6 +20,7 @@ <aspect name="kamon.instrumentation.NamedExecutorServiceFactoryDelegateInstrumentation"/>--> <aspect name="kamon.instrumentation.ActorSystemInstrumentation"/> <!--<aspect name ="kamon.instrumentation.ForkJoinPoolInstrumentation"/>--> + <aspect name="kamon.instrumentation.SprayRequestContextTracing"/> <aspect name = "kamon.instrumentation.SprayServerInstrumentation"/> diff --git a/kamon-core/src/main/scala/kamon/TraceContextSwap.scala b/kamon-core/src/main/scala/kamon/TraceContextSwap.scala index 4b5b66a9..c25e63d1 100644 --- a/kamon-core/src/main/scala/kamon/TraceContextSwap.scala +++ b/kamon-core/src/main/scala/kamon/TraceContextSwap.scala @@ -12,11 +12,11 @@ trait TraceContextSwap { def withContext[A](ctx: Option[TraceContext], primary: => A, fallback: => A): A = { ctx match { case Some(context) => { - MDC.put("uow", context.userContext.get.asInstanceOf[String]) + //MDC.put("uow", context.userContext.get.asInstanceOf[String]) Tracer.set(context) val bodyResult = primary Tracer.clear - MDC.remove("uow") + //MDC.remove("uow") bodyResult } diff --git a/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala index 4f0b8a08..fdd7b696 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/ActorRefTellInstrumentation.scala @@ -24,7 +24,7 @@ class ActorRefTellInstrumentation { @Around("sendingMessageToActorRef(actor, message, sender)") def around(pjp: ProceedingJoinPoint, actor: ActorRef, message: Any, sender: ActorRef): Unit = { import kamon.Instrument.instrumentation.sendMessageTransformation - + //println(s"====> [$sender] => [$actor] --- $message") pjp.proceedWithTarget(actor, sendMessageTransformation(sender, actor, message).asInstanceOf[AnyRef], sender) } } @@ -76,7 +76,7 @@ class UnregisteredActorRefInstrumentation { @Around("sprayResponderHandle(message, sender)") def sprayInvokeAround(pjp: ProceedingJoinPoint, message: Any, sender: ActorRef): Unit = { import ProceedingJoinPointPimp._ - println("Handling unregistered actor ref message: "+message) + //println("Handling unregistered actor ref message: "+message) message match { case SimpleTraceMessage(msg, ctx) => { ctx match { diff --git a/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala index 6573549d..f8ab709e 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/SprayServerInstrumentation.scala @@ -1,10 +1,12 @@ package kamon.instrumentation -import org.aspectj.lang.annotation.{After, Pointcut, Aspect} -import kamon.Tracer -import kamon.trace.UowTracing.{Finish, Rename} +import org.aspectj.lang.annotation.{DeclareMixin, After, Pointcut, Aspect} +import kamon.{TraceContext, Tracer} +import kamon.trace.UowTracing.{WebExternal, Finish, Rename} import spray.http.HttpRequest import spray.can.server.OpenRequestComponent +import spray.can.client.HttpHostConnector.RequestContext +import spray.http.HttpHeaders.Host @Aspect class SprayServerInstrumentation { @@ -17,7 +19,7 @@ class SprayServerInstrumentation { //@After("openRequestInit()") //def afterInit(): Unit = { Tracer.start - println("Created the context: " + Tracer.context() + " for the transaction: " + request.uri.path.toString()) + //println("Created the context: " + Tracer.context() + " for the transaction: " + request.uri.path.toString()) Tracer.context().map(_.entries ! Rename(request.uri.path.toString())) } @@ -30,4 +32,51 @@ class SprayServerInstrumentation { Tracer.context().map(_.entries ! Finish()) } + + + + + @Pointcut("execution(spray.can.client.HttpHostConnector.RequestContext.new(..)) && this(ctx)") + def requestRecordInit(ctx: TracingAwareRequestContext): Unit = {} + + @After("requestRecordInit(ctx)") + def whenCreatedRequestRecord(ctx: TracingAwareRequestContext): Unit = { + // Necessary to force the initialization of TracingAwareRequestContext at the moment of creation. + ctx.context + } + + + + + + + @Pointcut("execution(* spray.can.client.HttpHostConnectionSlot.dispatchToCommander(..)) && args(ctx, msg)") + def requestRecordInit2(ctx: TracingAwareRequestContext, msg: Any): Unit = {} + + @After("requestRecordInit2(ctx, msg)") + def whenCreatedRequestRecord2(ctx: TracingAwareRequestContext, msg: Any): Unit = { + println("=======> Spent in WEB External: " + (System.nanoTime() - ctx.timestamp)) + + // TODO: REMOVE THIS: + val request = (ctx.asInstanceOf[RequestContext]).request + + ctx.context.map(_.entries ! WebExternal(ctx.timestamp, System.nanoTime(), request.header[Host].map(_.host).getOrElse("UNKNOWN"))) + + } +} + +trait TracingAwareRequestContext { + def context: Option[TraceContext] + def timestamp: Long +} + +case class DefaultTracingAwareRequestContext(context: Option[TraceContext] = Tracer.context(), + timestamp: Long = System.nanoTime) extends TracingAwareRequestContext + + +@Aspect +class SprayRequestContextTracing { + + @DeclareMixin("spray.can.client.HttpHostConnector.RequestContext") + def mixin: TracingAwareRequestContext = DefaultTracingAwareRequestContext() }
\ No newline at end of file diff --git a/kamon-core/src/main/scala/kamon/newrelic/NewRelicReporting.scala b/kamon-core/src/main/scala/kamon/newrelic/NewRelicReporting.scala index 131ecba9..33f169da 100644 --- a/kamon-core/src/main/scala/kamon/newrelic/NewRelicReporting.scala +++ b/kamon-core/src/main/scala/kamon/newrelic/NewRelicReporting.scala @@ -3,6 +3,7 @@ package kamon.newrelic import akka.actor.Actor import kamon.trace.UowTrace import com.newrelic.api.agent.{Trace, NewRelic} +import kamon.trace.UowTracing.WebExternal class NewRelicReporting extends Actor { @@ -12,10 +13,28 @@ class NewRelicReporting extends Actor { //@Trace def recordTransaction(uowTrace: UowTrace): Unit = { - val time = (uowTrace.segments.last.timestamp - uowTrace.segments.head.timestamp)/1E9 + val time = ((uowTrace.segments.last.timestamp - uowTrace.segments.head.timestamp)/1E9) - NewRelic.recordMetric("WebTransaction/Custom" + uowTrace.name, time.toFloat) + NewRelic.recordMetric("WebTransaction/Custom" + uowTrace.name, time.toFloat ) NewRelic.recordMetric("WebTransaction", time.toFloat) NewRelic.recordMetric("HttpDispatcher", time.toFloat) + + uowTrace.segments.collect { case we: WebExternal => we }.foreach { webExternalTrace => + val external = ((webExternalTrace.end - webExternalTrace.start)/1E9).toFloat + NewRelic.recordMetric(s"External/all", external) + NewRelic.recordMetric(s"External/allWeb", external) + + NewRelic.recordMetric(s"Solr/all", 0.1F) + NewRelic.recordMetric(s"Solr/allWeb", 0.1F) + NewRelic.recordMetric(s"Solr/set", 0.1F) + NewRelic.recordMetric(s"Solr/set/WebTransaction/Custom/test", 0.1F) + + NewRelic.recordMetric(s"External/${webExternalTrace.host}/http", external) + NewRelic.recordMetric(s"External/${webExternalTrace.host}/all", external) + NewRelic.recordMetric(s"External/${webExternalTrace.host}/http/" + "WebTransaction/Custom" + uowTrace.name, external) + + + } + } } diff --git a/kamon-core/src/main/scala/kamon/trace/UowTracing.scala b/kamon-core/src/main/scala/kamon/trace/UowTracing.scala index b38d3d95..8efc46b2 100644 --- a/kamon-core/src/main/scala/kamon/trace/UowTracing.scala +++ b/kamon-core/src/main/scala/kamon/trace/UowTracing.scala @@ -16,6 +16,7 @@ object UowTracing { case class Start() extends AutoTimestamp case class Finish() extends AutoTimestamp case class Rename(name: String) extends AutoTimestamp + case class WebExternal(start: Long, end: Long, host: String) extends AutoTimestamp } case class UowTrace(name: String, segments: Seq[UowSegment]) diff --git a/kamon-core/src/main/scala/test/PingPong.scala b/kamon-core/src/main/scala/test/PingPong.scala index b78f1d79..93aa322d 100644 --- a/kamon-core/src/main/scala/test/PingPong.scala +++ b/kamon-core/src/main/scala/test/PingPong.scala @@ -4,6 +4,8 @@ import akka.actor.{Deploy, Props, Actor, ActorSystem} import java.util.concurrent.atomic.AtomicLong import kamon.Tracer import spray.routing.SimpleRoutingApp +import akka.util.Timeout +import spray.httpx.RequestBuilding object PingPong extends App { import scala.concurrent.duration._ @@ -49,13 +51,23 @@ class Ponger extends Actor { } -object SimpleRequestProcessor extends App with SimpleRoutingApp { +object SimpleRequestProcessor extends App with SimpleRoutingApp with RequestBuilding { + import scala.concurrent.duration._ + import spray.client.pipelining._ + implicit val system = ActorSystem("test") + import system.dispatcher + + implicit val timeout = Timeout(30 seconds) + + val pipeline = sendReceive startServer(interface = "localhost", port = 9090) { get { path("test"){ - complete("OK") + complete { + pipeline(Get("http://www.despegar.com.ar")).map(r => "Ok") + } } } } |