aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-12-17 14:19:23 -0300
committerDiego <diegolparra@gmail.com>2014-12-17 14:19:23 -0300
commitef0efc23b3b408a11fb52c77366bcd10ba66327a (patch)
tree4ad97f5de827b108eff3aa1d6e6c2ef961a65ae2
parent049b2822c569b4ea0b0c4c073631bdc0a340264d (diff)
downloadKamon-ef0efc23b3b408a11fb52c77366bcd10ba66327a.tar.gz
Kamon-ef0efc23b3b408a11fb52c77366bcd10ba66327a.tar.bz2
Kamon-ef0efc23b3b408a11fb52c77366bcd10ba66327a.zip
= core: avoid unnecesary allocation when askPatternTimeoutWarning is off
-rw-r--r--kamon-core/src/main/resources/reference.conf9
-rw-r--r--kamon-core/src/main/scala/kamon/akka/AkkaExtension.scala32
-rw-r--r--kamon-core/src/main/scala/kamon/instrumentation/akka/AskPatternInstrumentation.scala23
-rw-r--r--kamon-core/src/main/scala/kamon/trace/TraceExtension.scala3
-rw-r--r--kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala4
5 files changed, 54 insertions, 17 deletions
diff --git a/kamon-core/src/main/resources/reference.conf b/kamon-core/src/main/resources/reference.conf
index df5534a4..da09f500 100644
--- a/kamon-core/src/main/resources/reference.conf
+++ b/kamon-core/src/main/resources/reference.conf
@@ -172,13 +172,18 @@ kamon {
max-incubation-time = 20 seconds
}
- # If ask-pattern-tracing is enabled, a WARN level log message will be generated if a future generated by the `ask`
+ # Default dispatcher for all trace operations
+ dispatcher = ${kamon.default-dispatcher}
+ }
+
+ akka {
+ # If ask-pattern-timeout-warning is enabled, a WARN level log message will be generated if a future generated by the `ask`
# pattern fails with a `AskTimeoutException` and the log message will contain information depending of the strategy selected.
# strategies:
# - off: nothing to do.
# - lightweight: logs the warning when a timeout is reached using org.aspectj.lang.reflect.SourceLocation.
# - heavyweight: logs the warning when a timeout is reached using a stack trace captured at the moment the future was created.
- ask-pattern-tracing = off
+ ask-pattern-timeout-warning = off
# Default dispatcher for all trace operations
dispatcher = ${kamon.default-dispatcher}
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
diff --git a/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala b/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala
index e0c861cb..471cbd4d 100644
--- a/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala
+++ b/kamon-core/src/test/scala/kamon/instrumentation/akka/AskPatternInstrumentationSpec.scala
@@ -31,8 +31,8 @@ class AskPatternInstrumentationSpec extends TestKitBase with WordSpecLike with M
implicit lazy val system: ActorSystem = ActorSystem("ask-pattern-tracing-spec", ConfigFactory.parseString(
"""
|kamon {
- | trace {
- | ask-pattern-tracing = heavyweight
+ | akka {
+ | ask-pattern-timeout-warning = heavyweight
| }
|}
""".stripMargin))