aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2014-07-09 00:14:05 -0300
committerIvan Topolnjak <ivantopo@gmail.com>2014-07-09 00:14:05 -0300
commit7371ea60bfa60edcf64c119a969e705aaaa2ae4d (patch)
tree2dbb06753ccb177ee89442d3d3a3bf0ff1090e6a
parent2a90bdaaec12a3d2157909a2ab8840d81de3c984 (diff)
downloadKamon-7371ea60bfa60edcf64c119a969e705aaaa2ae4d.tar.gz
Kamon-7371ea60bfa60edcf64c119a969e705aaaa2ae4d.tar.bz2
Kamon-7371ea60bfa60edcf64c119a969e705aaaa2ae4d.zip
+ core: log a configurable error message when the application was started with the AspectJ Weaver, closes #48
-rw-r--r--kamon-core/src/main/resources/META-INF/aop.xml3
-rw-r--r--kamon-core/src/main/resources/reference.conf6
-rw-r--r--kamon-core/src/main/scala/kamon/instrumentation/AspectJWeaverMissingWarning.scala17
-rw-r--r--kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala29
4 files changed, 54 insertions, 1 deletions
diff --git a/kamon-core/src/main/resources/META-INF/aop.xml b/kamon-core/src/main/resources/META-INF/aop.xml
index e1edaed9..07f5cfd1 100644
--- a/kamon-core/src/main/resources/META-INF/aop.xml
+++ b/kamon-core/src/main/resources/META-INF/aop.xml
@@ -2,6 +2,9 @@
<aspectj>
<aspects>
+ <!-- Disable AspectJ Weaver not present error -->
+ <aspect name="kamon.instrumentation.AspectJWeaverMissingWarning"/>
+
<!-- Actors -->
<aspect name="akka.instrumentation.TraceContextIntoRepointableActorRefMixin"/>
<aspect name="akka.instrumentation.TraceContextIntoSystemMessageMixin"/>
diff --git a/kamon-core/src/main/resources/reference.conf b/kamon-core/src/main/resources/reference.conf
index 3c8f3686..b3df73bf 100644
--- a/kamon-core/src/main/resources/reference.conf
+++ b/kamon-core/src/main/resources/reference.conf
@@ -26,6 +26,12 @@ kamon {
# be allocated once and reused it shouldn't impose a memory footprint issue.
default-collection-context-buffer-size = 33792
+ # Disables a big error message that will be typically logged if your application wasn't started
+ # with the -javaagent:/path-to-aspectj-weaver.jar option. If you are only using KamonStandalone
+ # it might be ok for you to turn this error off.
+ disable-aspectj-weaver-missing-error = false
+
+
dispatchers {
# Dispatcher for periodical gauge value recordings.
diff --git a/kamon-core/src/main/scala/kamon/instrumentation/AspectJWeaverMissingWarning.scala b/kamon-core/src/main/scala/kamon/instrumentation/AspectJWeaverMissingWarning.scala
new file mode 100644
index 00000000..d227404a
--- /dev/null
+++ b/kamon-core/src/main/scala/kamon/instrumentation/AspectJWeaverMissingWarning.scala
@@ -0,0 +1,17 @@
+package kamon.instrumentation
+
+import _root_.akka.event.EventStream
+import org.aspectj.lang.ProceedingJoinPoint
+import org.aspectj.lang.annotation.{Around, Pointcut, Aspect}
+
+@Aspect
+class AspectJWeaverMissingWarning {
+
+ @Pointcut("execution(* kamon.metric.MetricsExtension.printInitializationMessage(..)) && args(eventStream, *)")
+ def printInitializationMessage(eventStream: EventStream): Unit = {}
+
+ @Around("printInitializationMessage(eventStream)")
+ def aroundPrintInitializationMessage(pjp: ProceedingJoinPoint, eventStream: EventStream): Unit = {
+ pjp.proceed(Array[AnyRef](eventStream, Boolean.box(true)))
+ }
+}
diff --git a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
index 8c6d0359..3465fef9 100644
--- a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
+++ b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
@@ -16,7 +16,8 @@
package kamon.metric
-import java.nio.{ LongBuffer, ByteBuffer }
+import akka.event.Logging.Error
+import akka.event.EventStream
import scala.collection.concurrent.TrieMap
import akka.actor._
@@ -30,6 +31,7 @@ import java.util.concurrent.TimeUnit
class MetricsExtension(system: ExtendedActorSystem) extends Kamon.Extension {
val metricsExtConfig = system.settings.config.getConfig("kamon.metrics")
+ printInitializationMessage(system.eventStream, metricsExtConfig.getBoolean("disable-aspectj-weaver-missing-error"))
/** Configured Dispatchers */
val metricSubscriptionsDispatcher = system.dispatchers.lookup(metricsExtConfig.getString("dispatchers.metric-subscriptions"))
@@ -93,6 +95,31 @@ class MetricsExtension(system: ExtendedActorSystem) extends Kamon.Extension {
def buildDefaultCollectionContext: CollectionContext =
CollectionContext(metricsExtConfig.getInt("default-collection-context-buffer-size"))
+
+ def printInitializationMessage(eventStream: EventStream, disableWeaverMissingError: Boolean): Unit = {
+ if(!disableWeaverMissingError) {
+ val weaverMissingMessage =
+ """
+ |
+ | ___ _ ___ _ _ ___ ___ _ _
+ | / _ \ | | |_ | | | | | | \/ |(_) (_)
+ |/ /_\ \ ___ _ __ ___ ___ | |_ | | | | | | ___ __ _ __ __ ___ _ __ | . . | _ ___ ___ _ _ __ __ _
+ || _ |/ __|| '_ \ / _ \ / __|| __| | | | |/\| | / _ \ / _` |\ \ / // _ \| '__| | |\/| || |/ __|/ __|| || '_ \ / _` |
+ || | | |\__ \| |_) || __/| (__ | |_ /\__/ / \ /\ /| __/| (_| | \ V /| __/| | | | | || |\__ \\__ \| || | | || (_| |
+ |\_| |_/|___/| .__/ \___| \___| \__|\____/ \/ \/ \___| \__,_| \_/ \___||_| \_| |_/|_||___/|___/|_||_| |_| \__, |
+ | | | __/ |
+ | |_| |___/
+ |
+ | It seems like your application wasn't started with the -javaagent:/path-to-aspectj-weaver.jar option. Without that Kamon might
+ | not work properly, if you need help on setting up the weaver go to http://kamon.io/introduction/get-started/ for more info. If
+ | you are sure that you don't need the weaver (e.g. you are only using KamonStandalone) then you can disable this error message
+ | by changing the kamon.metrics.disable-aspectj-weaver-missing-error setting in your configuration file.
+ |
+ """.stripMargin
+
+ eventStream.publish(Error("MetricsExtension", classOf[MetricsExtension], weaverMissingMessage))
+ }
+ }
}
object Metrics extends ExtensionId[MetricsExtension] with ExtensionIdProvider {