diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-08-24 13:34:56 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-08-24 13:34:56 +0200 |
commit | 4da20e3ccfcd4094cde39acc932f72ece2b7780b (patch) | |
tree | 89e70aab4b6e720a9a80a4cf7df20903907aed68 /kamon-core/src/main/scala/kamon | |
parent | 363b410856f2aed1de8a0e9cfe1c13a3d3d25d02 (diff) | |
parent | cfb25accce7ad5b0592a206addc872b0d9242bd9 (diff) | |
download | Kamon-4da20e3ccfcd4094cde39acc932f72ece2b7780b.tar.gz Kamon-4da20e3ccfcd4094cde39acc932f72ece2b7780b.tar.bz2 Kamon-4da20e3ccfcd4094cde39acc932f72ece2b7780b.zip |
Merge branch 'make-kamon-test-friendly'
Conflicts:
kamon-core/src/main/scala/kamon/Kamon.scala
project/Settings.scala
Diffstat (limited to 'kamon-core/src/main/scala/kamon')
-rw-r--r-- | kamon-core/src/main/scala/kamon/Kamon.scala | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala index f9232a20..1c560d9f 100644 --- a/kamon-core/src/main/scala/kamon/Kamon.scala +++ b/kamon-core/src/main/scala/kamon/Kamon.scala @@ -16,6 +16,7 @@ package kamon import _root_.akka.actor import _root_.akka.actor._ +import _root_.akka.event.Logging import com.typesafe.config.{ ConfigFactory, Config } import kamon.metric._ import kamon.trace.{ TracerModuleImpl, TracerModule } @@ -25,10 +26,14 @@ object Kamon { private case class KamonCoreComponents(metrics: MetricsModule, tracer: TracerModule) + private val shouldAutoStart = isSystemPropertyEnabled("kamon.auto-start") + private val shouldWarnOnDuplicateStart = !isSystemPropertyEnabled("kamon.disable-duplicate-start-warning") + @volatile private var _system: ActorSystem = _ @volatile private var _coreComponents: Option[KamonCoreComponents] = None def start(config: Config): Unit = synchronized { + def resolveInternalConfig: Config = { val internalConfig = config.getConfig("kamon.internal-config") @@ -49,9 +54,15 @@ object Kamon { tracer.start(_system) _system.registerExtension(ModuleLoader) - } else sys.error("Kamon has already been started.") + } else if (shouldWarnOnDuplicateStart) { + val logger = Logging(_system, "Kamon") + logger.warning("An attempt to start Kamon has been made, but Kamon has already been started.") + } } + private def isSystemPropertyEnabled(propertyName: String): Boolean = + sys.props.get(propertyName).map(_.equals("true")).getOrElse(false) + def start(): Unit = start(ConfigFactory.load) @@ -79,7 +90,14 @@ object Kamon { apply(key) private def ifStarted[T](thunk: KamonCoreComponents ⇒ T): T = - _coreComponents.map(thunk(_)) getOrElse sys.error("Kamon has not been started yet.") + _coreComponents.map(thunk(_)) getOrElse { + if (shouldAutoStart) { + start() + thunk(_coreComponents.get) + + } else sys.error("Kamon has not been started yet. You must either explicitlt call Kamon.start(...) or enable " + + "automatic startup by adding -Dkamon.auto-start=true to your JVM options.") + } } |