diff options
Diffstat (limited to 'kamon-core/src/main/scala')
3 files changed, 45 insertions, 13 deletions
diff --git a/kamon-core/src/main/scala/kamon/akka/AkkaExtension.scala b/kamon-core/src/main/scala/kamon/akka/AkkaExtension.scala new file mode 100644 index 00000000..2fc7395e --- /dev/null +++ b/kamon-core/src/main/scala/kamon/akka/AkkaExtension.scala @@ -0,0 +1,32 @@ +/* + * ========================================================================================= + * Copyright © 2013-2014 the kamon project <http://kamon.io/> + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + * ========================================================================================= + */ +// +package kamon.extension.akka + +import akka.actor +import akka.actor._ +import kamon._ + +class AkkaExtension(system: ExtendedActorSystem) extends Kamon.Extension { + val config = system.settings.config.getConfig("kamon.akka") + val askPatternTimeoutWarning = config.getString("ask-pattern-timeout-warning") + val dispatcher = system.dispatchers.lookup(config.getString("dispatcher")) +} + +object Akka extends ExtensionId[AkkaExtension] with ExtensionIdProvider { + def lookup(): ExtensionId[_ <: actor.Extension] = Akka + def createExtension(system: ExtendedActorSystem): AkkaExtension = new AkkaExtension(system) +}
\ No newline at end of file diff --git a/kamon-core/src/main/scala/kamon/instrumentation/akka/AskPatternInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/akka/AskPatternInstrumentation.scala index efce169d..93b53764 100644 --- a/kamon-core/src/main/scala/kamon/instrumentation/akka/AskPatternInstrumentation.scala +++ b/kamon-core/src/main/scala/kamon/instrumentation/akka/AskPatternInstrumentation.scala @@ -17,7 +17,8 @@ package akka.kamon.instrumentation import kamon.Kamon -import kamon.trace.{ Trace, TraceContextAware } +import kamon.extension.akka.Akka +import kamon.trace.TraceContextAware import akka.actor.{ ActorSystem, ActorRef } import akka.event.Logging.Warning import akka.pattern.AskTimeoutException @@ -41,17 +42,18 @@ class AskPatternInstrumentation { @Around("askableActorRefAsk(ctx, actor)") def hookAskTimeoutWarning(pjp: ProceedingJoinPoint, ctx: TraceContextAware, actor: ActorRef): AnyRef = { implicit val system = ctx.traceContext.system - val traceExtension = Kamon(Trace)(system) + val akkaExtension = Kamon(Akka)(system) val future = pjp.proceed().asInstanceOf[Future[AnyRef]] - val handler = traceExtension.askPatternTracing match { - case "off" ⇒ errorHandler() - case "lightweight" ⇒ errorHandler(callInfo = Some(CallInfo(s"${actor.path.name} ?", pjp.getSourceLocation))) - case "heavyweight" ⇒ errorHandler(stack = Some(new StackTraceCaptureException)) + val handler = akkaExtension.askPatternTimeoutWarning match { + case "off" ⇒ None + case "lightweight" ⇒ Some(errorHandler(callInfo = Some(CallInfo(s"${actor.path.name} ?", pjp.getSourceLocation)))) + case "heavyweight" ⇒ Some(errorHandler(stack = Some(new StackTraceCaptureException))) } - future.onFailure(handler)(traceExtension.defaultDispatcher) + handler.map(h ⇒ future.onFailure(h)(akkaExtension.dispatcher)) + future } @@ -64,10 +66,9 @@ class AskPatternInstrumentation { publish(message) } - def publish(message: Option[String])(implicit system: ActorSystem) = message map { - msg ⇒ - system.eventStream.publish(Warning("AskPatternTracing", classOf[AskPatternInstrumentation], - s"Timeout triggered for ask pattern registered at: $msg")) + def publish(message: Option[String])(implicit system: ActorSystem) = message map { msg ⇒ + system.eventStream.publish(Warning("AskPatternTracing", classOf[AskPatternInstrumentation], + s"Timeout triggered for ask pattern registered at: $msg")) } } diff --git a/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala b/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala index c227ce58..41f022d0 100644 --- a/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala +++ b/kamon-core/src/main/scala/kamon/trace/TraceExtension.scala @@ -27,8 +27,7 @@ import kamon.util.GlobPathFilter class TraceExtension(system: ExtendedActorSystem) extends Kamon.Extension { val config = system.settings.config.getConfig("kamon.trace") - val askPatternTracing = config.getString("ask-pattern-tracing") - val defaultDispatcher = system.dispatchers.lookup(config.getString("dispatcher")) + val dispatcher = system.dispatchers.lookup(config.getString("dispatcher")) val detailLevel: LevelOfDetail = config.getString("level") match { case "metrics-only" ⇒ LevelOfDetail.MetricsOnly |