diff options
author | Diego Parra <diegolparra@gmail.com> | 2013-11-26 15:54:10 -0300 |
---|---|---|
committer | Diego Parra <diegolparra@gmail.com> | 2013-11-26 15:54:10 -0300 |
commit | 5e0b032bfef9509e64af2960452aed44b6e6cb22 (patch) | |
tree | 464573c5093b966eaddc65b52244bb1b50c03857 /kamon-trace/src/main/scala/kamon/trace | |
parent | dad8547a63d65a5b929346310d53ba2ab45d615c (diff) | |
download | Kamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.tar.gz Kamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.tar.bz2 Kamon-5e0b032bfef9509e64af2960452aed44b6e6cb22.zip |
added scalariform
Diffstat (limited to 'kamon-trace/src/main/scala/kamon/trace')
6 files changed, 24 insertions, 34 deletions
diff --git a/kamon-trace/src/main/scala/kamon/trace/Trace.scala b/kamon-trace/src/main/scala/kamon/trace/Trace.scala index d733c5de..05519067 100644 --- a/kamon-trace/src/main/scala/kamon/trace/Trace.scala +++ b/kamon-trace/src/main/scala/kamon/trace/Trace.scala @@ -27,17 +27,13 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { def lookup(): ExtensionId[_ <: Extension] = Trace def createExtension(system: ExtendedActorSystem): TraceExtension = new TraceExtension(system) - /*** Protocol */ case object Register - - /** User API */ private[trace] val traceContext = new DynamicVariable[Option[TraceContext]](None) private[trace] val tranid = new AtomicLong() - def context() = traceContext.value def set(ctx: TraceContext) = traceContext.value = Some(ctx) @@ -50,9 +46,9 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { ctx } - def withContext[T](ctx: Option[TraceContext])(thunk: => T): T = traceContext.withValue(ctx)(thunk) + def withContext[T](ctx: Option[TraceContext])(thunk: ⇒ T): T = traceContext.withValue(ctx)(thunk) - def transformContext(f: TraceContext => TraceContext): Unit = { + def transformContext(f: TraceContext ⇒ TraceContext): Unit = { context.map(f).foreach(set(_)) } @@ -74,16 +70,16 @@ class TraceManager extends Actor with ActorLogging { var listeners: Seq[ActorRef] = Seq.empty def receive = { - case Register => + case Register ⇒ listeners = sender +: listeners log.info("Registered [{}] as listener for Kamon traces", sender) - case segment: UowSegment => + case segment: UowSegment ⇒ val tracerName = segment.id.toString context.child(tracerName).getOrElse(newTracer(tracerName)) ! segment - case trace: UowTrace => - listeners foreach(_ ! trace) + case trace: UowTrace ⇒ + listeners foreach (_ ! trace) } def newTracer(name: String): ActorRef = { diff --git a/kamon-trace/src/main/scala/kamon/trace/TraceContext.scala b/kamon-trace/src/main/scala/kamon/trace/TraceContext.scala index c1efd847..eee3e0b0 100644 --- a/kamon-trace/src/main/scala/kamon/trace/TraceContext.scala +++ b/kamon-trace/src/main/scala/kamon/trace/TraceContext.scala @@ -20,7 +20,7 @@ import akka.actor._ import java.util.concurrent.atomic.AtomicLong import scala.concurrent.duration._ import kamon.Kamon -import kamon.trace.UowTracing.{Finish, Start} +import kamon.trace.UowTracing.{ Finish, Start } // TODO: Decide if we need or not an ID, generating it takes time and it doesn't seem necessary. protected[kamon] case class TraceContext(private val collector: ActorRef, id: Long, uow: String = "", userContext: Option[Any] = None) { @@ -31,10 +31,8 @@ protected[kamon] case class TraceContext(private val collector: ActorRef, id: Lo collector ! Finish(id) } - } - trait ContextAware { def traceContext: Option[TraceContext] } diff --git a/kamon-trace/src/main/scala/kamon/trace/UowTracing.scala b/kamon-trace/src/main/scala/kamon/trace/UowTracing.scala index a9603585..7858e31f 100644 --- a/kamon-trace/src/main/scala/kamon/trace/UowTracing.scala +++ b/kamon-trace/src/main/scala/kamon/trace/UowTracing.scala @@ -41,7 +41,6 @@ case class UowTrace(name: String, uow: String, start: Long, end: Long, segments: def elapsed: Long = end - start } - class UowTraceAggregator(reporting: ActorRef, aggregationTimeout: Duration) extends Actor with ActorLogging { context.setReceiveTimeout(aggregationTimeout) @@ -54,20 +53,20 @@ class UowTraceAggregator(reporting: ActorRef, aggregationTimeout: Duration) exte var end = 0L def receive = { - case start: Start => + case start: Start ⇒ this.start = start.timestamp segments = segments :+ start; name = start.name - case finish: Finish => + case finish: Finish ⇒ end = finish.timestamp segments = segments :+ finish; finishTracing() - case wes: WebExternalStart => pendingExternal = pendingExternal :+ wes - case finish @ WebExternalFinish(id) => pendingExternal.find(_.id == id).map(start => { + case wes: WebExternalStart ⇒ pendingExternal = pendingExternal :+ wes + case finish @ WebExternalFinish(id) ⇒ pendingExternal.find(_.id == id).map(start ⇒ { segments = segments :+ WebExternal(finish.id, start.timestamp, finish.timestamp, start.host) }) - case Rename(id, newName) => name = newName - case segment: UowSegment => segments = segments :+ segment - case ReceiveTimeout => + case Rename(id, newName) ⇒ name = newName + case segment: UowSegment ⇒ segments = segments :+ segment + case ReceiveTimeout ⇒ log.warning("Transaction {} did not complete properly, the recorded segments are: {}", name, segments) context.stop(self) } diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingTracing.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingTracing.scala index c1a0d228..783fd6e1 100644 --- a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingTracing.scala +++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingTracing.scala @@ -15,10 +15,10 @@ * ========================================================== */ package kamon.trace.instrumentation -import org.aspectj.lang.annotation.{Around, Pointcut, DeclareMixin, Aspect} +import org.aspectj.lang.annotation.{ Around, Pointcut, DeclareMixin, Aspect } import org.aspectj.lang.ProceedingJoinPoint import org.slf4j.MDC -import kamon.trace.{TraceContext, ContextAware, Trace} +import kamon.trace.{ TraceContext, ContextAware, Trace } @Aspect class ActorLoggingTracing { @@ -27,17 +27,17 @@ class ActorLoggingTracing { def mixin: ContextAware = ContextAware.default @Pointcut("execution(* akka.event.slf4j.Slf4jLogger.withMdc(..)) && args(logSource, logEvent, logStatement)") - def withMdcInvocation(logSource: String, logEvent: ContextAware, logStatement: () => _): Unit = {} + def withMdcInvocation(logSource: String, logEvent: ContextAware, logStatement: () ⇒ _): Unit = {} @Around("withMdcInvocation(logSource, logEvent, logStatement)") - def aroundWithMdcInvocation(pjp: ProceedingJoinPoint, logSource: String, logEvent: ContextAware, logStatement: () => _): Unit = { + def aroundWithMdcInvocation(pjp: ProceedingJoinPoint, logSource: String, logEvent: ContextAware, logStatement: () ⇒ _): Unit = { logEvent.traceContext match { - case Some(ctx) => + case Some(ctx) ⇒ MDC.put("uow", ctx.uow) pjp.proceed() MDC.remove("uow") - case None => pjp.proceed() + case None ⇒ pjp.proceed() } } } diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorMessagePassingTracing.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorMessagePassingTracing.scala index 4b48f8f2..399ddf61 100644 --- a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorMessagePassingTracing.scala +++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorMessagePassingTracing.scala @@ -17,11 +17,10 @@ package kamon.trace.instrumentation import org.aspectj.lang.annotation._ import org.aspectj.lang.ProceedingJoinPoint -import akka.actor.{Props, ActorSystem, ActorRef} -import akka.dispatch.{Envelope, MessageDispatcher} +import akka.actor.{ Props, ActorSystem, ActorRef } +import akka.dispatch.{ Envelope, MessageDispatcher } import com.codahale.metrics.Timer -import kamon.trace.{ContextAware, TraceContext, Trace} - +import kamon.trace.{ ContextAware, TraceContext, Trace } @Aspect class BehaviourInvokeTracing { diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala index fc4abfe3..844f1d61 100644 --- a/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala +++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/FutureTracing.scala @@ -17,7 +17,7 @@ package kamon.trace.instrumentation import org.aspectj.lang.annotation._ import org.aspectj.lang.ProceedingJoinPoint -import kamon.trace.{ContextAware, TraceContext, Trace} +import kamon.trace.{ ContextAware, TraceContext, Trace } @Aspect class FutureTracing { @@ -25,7 +25,6 @@ class FutureTracing { @DeclareMixin("scala.concurrent.impl.CallbackRunnable || scala.concurrent.impl.Future.PromiseCompletingRunnable") def mixin: ContextAware = ContextAware.default - @Pointcut("execution((scala.concurrent.impl.CallbackRunnable || scala.concurrent.impl.Future.PromiseCompletingRunnable).new(..)) && this(runnable)") def futureRelatedRunnableCreation(runnable: ContextAware): Unit = {} @@ -35,7 +34,6 @@ class FutureTracing { runnable.traceContext } - @Pointcut("execution(* (scala.concurrent.impl.CallbackRunnable || scala.concurrent.impl.Future.PromiseCompletingRunnable).run()) && this(runnable)") def futureRelatedRunnableExecution(runnable: ContextAware) = {} |