diff options
author | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-12 18:15:00 -0300 |
---|---|---|
committer | Ivan Topolnak <ivantopo@gmail.com> | 2013-11-12 18:15:00 -0300 |
commit | ef8ef647162b5f3eb9033bafb87805e2de5f576e (patch) | |
tree | b7c0d86e6519b497903152d23c307652f0e3a2f5 /kamon-trace/src/main/scala/kamon | |
parent | 5c8eb362ea6a957449419cec6c48b54159d4c68e (diff) | |
download | Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.tar.gz Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.tar.bz2 Kamon-ef8ef647162b5f3eb9033bafb87805e2de5f576e.zip |
Initial ask pattern tracing
Diffstat (limited to 'kamon-trace/src/main/scala/kamon')
3 files changed, 40 insertions, 6 deletions
diff --git a/kamon-trace/src/main/scala/kamon/trace/Trace.scala b/kamon-trace/src/main/scala/kamon/trace/Trace.scala index d5bb1ddf..0ef438d4 100644 --- a/kamon-trace/src/main/scala/kamon/trace/Trace.scala +++ b/kamon-trace/src/main/scala/kamon/trace/Trace.scala @@ -27,10 +27,12 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { def set(ctx: TraceContext) = traceContext.value = Some(ctx) def clear: Unit = traceContext.value = None - def start(name: String)(implicit system: ActorSystem) = { - val ctx = newTraceContext() + def start(name: String)(implicit system: ActorSystem): TraceContext = { + val ctx = newTraceContext(name) ctx.start(name) set(ctx) + + ctx } def transformContext(f: TraceContext => TraceContext): Unit = { @@ -44,7 +46,7 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { } // TODO: FIX - def newTraceContext()(implicit system: ActorSystem): TraceContext = TraceContext(Kamon(Trace), tranid.getAndIncrement) + def newTraceContext(name: String)(implicit system: ActorSystem): TraceContext = TraceContext(Kamon(Trace), tranid.getAndIncrement, name) } class TraceExtension(system: ExtendedActorSystem) extends Kamon.Extension { diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingInstrumentation.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingInstrumentation.scala index 77993cdd..fecdc7e3 100644 --- a/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingInstrumentation.scala +++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingInstrumentation.scala @@ -10,9 +10,7 @@ class ActorLoggingInstrumentation { @DeclareMixin("akka.event.Logging.LogEvent+") - def traceContextMixin: ContextAware = new ContextAware { - def traceContext: Option[TraceContext] = Trace.context() - } + def traceContextMixin: ContextAware = ContextAware.default @Pointcut("execution(* akka.event.slf4j.Slf4jLogger.withMdc(..)) && args(logSource, logEvent, logStatement)") def withMdcInvocation(logSource: String, logEvent: ContextAware, logStatement: () => _): Unit = {} diff --git a/kamon-trace/src/main/scala/kamon/trace/instrumentation/AskPatternTracing.scala b/kamon-trace/src/main/scala/kamon/trace/instrumentation/AskPatternTracing.scala new file mode 100644 index 00000000..625ed1ae --- /dev/null +++ b/kamon-trace/src/main/scala/kamon/trace/instrumentation/AskPatternTracing.scala @@ -0,0 +1,34 @@ +package akka.pattern.tracing + +import org.aspectj.lang.annotation.{After, AfterReturning, Pointcut, Aspect} +import akka.pattern.{AskTimeoutException, PromiseActorRef} +import akka.event.Logging.Warning +import scala.compat.Platform.EOL +import akka.actor.ActorRefProvider + +@Aspect +class AskPatternTracing { + + class StackTraceCaptureException extends Throwable + + @Pointcut(value = "execution(* akka.pattern.PromiseActorRef$.apply(..)) && args(provider, *)", argNames = "provider") + def promiseActorRefApply(provider: ActorRefProvider): Unit = { + provider.settings.config.getBoolean("kamon.trace.ask-pattern-tracing") + } + + @AfterReturning(pointcut = "promiseActorRefApply(provider)", returning = "promiseActor") + def hookAskTimeoutWarning(provider: ActorRefProvider, promiseActor: PromiseActorRef): Unit = { + val future = promiseActor.result.future + val system = promiseActor.provider.guardian.underlying.system + implicit val ec = system.dispatcher + val stack = new StackTraceCaptureException + + future onFailure { + case timeout: AskTimeoutException => + val stackString = stack.getStackTrace.drop(3).mkString("", EOL, EOL) + + system.eventStream.publish(Warning("AskPatternTracing", classOf[AskPatternTracing], + "Timeout triggered for ask pattern registered at: " + stackString)) + } + } +} |