aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/Kamon.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2018-08-30 10:40:53 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2018-08-30 10:40:53 +0200
commite4abea098ef4d6e71a805812bfa95c14bd9002b5 (patch)
treef5fcb8222e293f420a9e7c06953805a7428d0f0e /kamon-core/src/main/scala/kamon/Kamon.scala
parent794fbf02664ac8c31072d8b955d897901f1f22e0 (diff)
downloadKamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.tar.gz
Kamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.tar.bz2
Kamon-e4abea098ef4d6e71a805812bfa95c14bd9002b5.zip
working on context tags and http propagation improvements
Diffstat (limited to 'kamon-core/src/main/scala/kamon/Kamon.scala')
-rw-r--r--kamon-core/src/main/scala/kamon/Kamon.scala69
1 files changed, 5 insertions, 64 deletions
diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala
index 8f69ab41..2825d961 100644
--- a/kamon-core/src/main/scala/kamon/Kamon.scala
+++ b/kamon-core/src/main/scala/kamon/Kamon.scala
@@ -19,7 +19,7 @@ import java.time.Duration
import java.util.concurrent.{Executors, ScheduledExecutorService, ScheduledThreadPoolExecutor}
import com.typesafe.config.{Config, ConfigFactory}
-import kamon.context.{Codecs, Context, Key, Storage}
+import kamon.context.Codecs
import kamon.metric._
import kamon.trace._
import kamon.util.{Clock, Filters, Matcher, Registration}
@@ -29,7 +29,7 @@ import scala.concurrent.Future
import scala.util.Try
-object Kamon extends MetricLookup with ReporterRegistry with Tracer {
+object Kamon extends MetricLookup with ClassLoading with Configuration with ReporterRegistry with Tracer with ContextPropagation with ContextStorage {
private val logger = LoggerFactory.getLogger("kamon.Kamon")
@volatile private var _config = ConfigFactory.load()
@@ -41,19 +41,15 @@ object Kamon extends MetricLookup with ReporterRegistry with Tracer {
private val _metrics = new MetricRegistry(_config, _scheduler)
private val _reporterRegistry = new ReporterRegistry.Default(_metrics, _config, _clock)
private val _tracer = Tracer.Default(Kamon, _reporterRegistry, _config, _clock)
- private val _contextStorage = Storage.ThreadLocal()
private val _contextCodec = new Codecs(_config)
- private var _onReconfigureHooks = Seq.empty[OnReconfigureHook]
+ //private var _onReconfigureHooks = Seq.empty[OnReconfigureHook]
sys.addShutdownHook(() => _scheduler.shutdown())
def environment: Environment =
_environment
- def config(): Config =
- _config
-
- def reconfigure(config: Config): Unit = synchronized {
+ onReconfigure(newConfig => {
_config = config
_environment = Environment.fromConfig(config)
_filters = Filters.fromConfig(config)
@@ -62,18 +58,11 @@ object Kamon extends MetricLookup with ReporterRegistry with Tracer {
_tracer.reconfigure(config)
_contextCodec.reconfigure(config)
- _onReconfigureHooks.foreach(hook => {
- Try(hook.onReconfigure(config)).failed.foreach(error =>
- logger.error("Exception occurred while trying to run a OnReconfigureHook", error)
- )
- })
-
_scheduler match {
case stpe: ScheduledThreadPoolExecutor => stpe.setCorePoolSize(schedulerPoolSize(config))
case other => logger.error("Unexpected scheduler [{}] found when reconfiguring Kamon.", other)
}
- }
-
+ })
override def histogram(name: String, unit: MeasurementUnit, dynamicRange: Option[DynamicRange]): HistogramMetric =
_metrics.histogram(name, unit, dynamicRange)
@@ -105,43 +94,7 @@ object Kamon extends MetricLookup with ReporterRegistry with Tracer {
def contextCodec(): Codecs =
_contextCodec
- def currentContext(): Context =
- _contextStorage.current()
-
- def currentSpan(): Span =
- _contextStorage.current().get(Span.ContextKey)
-
- def storeContext(context: Context): Storage.Scope =
- _contextStorage.store(context)
-
- def withContext[T](context: Context)(f: => T): T = {
- val scope = _contextStorage.store(context)
- try {
- f
- } finally {
- scope.close()
- }
- }
-
- def withContextKey[T, K](key: Key[K], value: K)(f: => T): T =
- withContext(currentContext().withKey(key, value))(f)
-
- def withSpan[T](span: Span)(f: => T): T =
- withSpan(span, true)(f)
- def withSpan[T](span: Span, finishSpan: Boolean)(f: => T): T = {
- try {
- withContextKey(Span.ContextKey, span)(f)
- } catch {
- case t: Throwable =>
- span.addError(t.getMessage, t)
- throw t
-
- } finally {
- if(finishSpan)
- span.finish()
- }
- }
override def loadReportersFromConfig(): Unit =
_reporterRegistry.loadReportersFromConfig()
@@ -173,14 +126,6 @@ object Kamon extends MetricLookup with ReporterRegistry with Tracer {
def clock(): Clock =
_clock
- /**
- * Register a reconfigure hook that will be run when the a call to Kamon.reconfigure(config) is performed. All
- * registered hooks will run sequentially in the same Thread that calls Kamon.reconfigure(config).
- */
- def onReconfigure(hook: OnReconfigureHook): Unit = synchronized {
- _onReconfigureHooks = hook +: _onReconfigureHooks
- }
-
def scheduler(): ScheduledExecutorService =
_scheduler
@@ -188,7 +133,3 @@ object Kamon extends MetricLookup with ReporterRegistry with Tracer {
config.getInt("kamon.scheduler-pool-size")
}
-
-trait OnReconfigureHook {
- def onReconfigure(newConfig: Config): Unit
-}