aboutsummaryrefslogtreecommitdiff
path: root/kamon-trace/src/main/scala/kamon/trace/instrumentation
diff options
context:
space:
mode:
Diffstat (limited to 'kamon-trace/src/main/scala/kamon/trace/instrumentation')
-rw-r--r--kamon-trace/src/main/scala/kamon/trace/instrumentation/ActorLoggingInstrumentation.scala4
-rw-r--r--kamon-trace/src/main/scala/kamon/trace/instrumentation/AskPatternTracing.scala34
2 files changed, 35 insertions, 3 deletions
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))
+ }
+ }
+}