From b2b43016b2b652ebcd686959048e3c5fe427e649 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Thu, 8 Jun 2017 16:05:32 +0200 Subject: expose all apis through the Kamon companion object --- kamon-core/src/main/scala/kamon/Kamon.scala | 54 ++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'kamon-core/src/main/scala/kamon/Kamon.scala') diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala index 3a85be0a..be63890d 100644 --- a/kamon-core/src/main/scala/kamon/Kamon.scala +++ b/kamon-core/src/main/scala/kamon/Kamon.scala @@ -3,29 +3,26 @@ package kamon import java.util.concurrent.atomic.AtomicReference import com.typesafe.config.{Config, ConfigFactory} +import io.opentracing.propagation.Format +import io.opentracing.{ActiveSpan, Span, SpanContext} import kamon.metric._ import kamon.trace.Tracer import kamon.util.{HexCodec, MeasurementUnit} +import scala.concurrent.Future import scala.concurrent.duration.Duration import scala.concurrent.forkjoin.ThreadLocalRandom -object Kamon extends MetricLookup { +object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Tracer { private val initialConfig = ConfigFactory.load() private val incarnation = HexCodec.toLowerHex(ThreadLocalRandom.current().nextLong()) private val metricRegistry = new MetricRegistry(initialConfig) private val reporterRegistry = new ReporterRegistryImpl(metricRegistry, initialConfig) - private val trazer = new Tracer(Kamon, reporterRegistry) + private val tracer = new Tracer(Kamon, reporterRegistry) private val env = new AtomicReference[Environment](environmentFromConfig(ConfigFactory.load())) - def tracer: io.opentracing.Tracer = - trazer - - def reporters: ReporterRegistry = - reporterRegistry - def environment: Environment = env.get() @@ -36,6 +33,7 @@ object Kamon extends MetricLookup { } + override def histogram(name: String, unit: MeasurementUnit, tags: Map[String, String], dynamicRange: Option[DynamicRange]): Histogram = metricRegistry.histogram(name, unit, tags, dynamicRange) @@ -51,7 +49,45 @@ object Kamon extends MetricLookup { metricRegistry.minMaxCounter(name, unit, tags, dynamicRange, sampleInterval) - case class Environment(config: Config, application: String, host: String, instance: String, incarnation: String) + + override def buildSpan(operationName: String): io.opentracing.Tracer.SpanBuilder = + tracer.buildSpan(operationName) + + override def extract[C](format: Format[C], carrier: C): SpanContext = + tracer.extract(format, carrier) + + override def inject[C](spanContext: SpanContext, format: Format[C], carrier: C): Unit = + tracer.inject(spanContext, format, carrier) + + override def activeSpan(): ActiveSpan = + tracer.activeSpan() + + override def makeActive(span: Span): ActiveSpan = + tracer.makeActive(span) + + + + override def loadReportersFromConfig(): Unit = + reporterRegistry.loadReportersFromConfig() + + override def addReporter(reporter: MetricReporter): Registration = + reporterRegistry.addReporter(reporter) + + override def addReporter(reporter: MetricReporter, name: String): Registration = + reporterRegistry.addReporter(reporter, name) + + override def addReporter(reporter: SpanReporter): Registration = + reporterRegistry.addReporter(reporter) + + override def addReporter(reporter: SpanReporter, name: String): Registration = + reporterRegistry.addReporter(reporter, name) + + override def stopAllReporters(): Future[Unit] = + reporterRegistry.stopAllReporters() + + + + case class Environment(config: Config, application: String, host: String, instance: String, incarnation: String) private def environmentFromConfig(config: Config): Environment = { val environmentConfig = config.getConfig("kamon.environment") -- cgit v1.2.3