aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/ReporterRegistry.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-06-18 12:38:09 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-06-18 12:38:09 +0200
commit1d98b9e8a397acf8b6f6f55a3fd5189eb72740ba (patch)
treeb97f219f1714756672310be61b132015a024944a /kamon-core/src/main/scala/kamon/ReporterRegistry.scala
parent9119413d8dc9b26874e85d8a5f3b135379b9f6da (diff)
downloadKamon-1d98b9e8a397acf8b6f6f55a3fd5189eb72740ba.tar.gz
Kamon-1d98b9e8a397acf8b6f6f55a3fd5189eb72740ba.tar.bz2
Kamon-1d98b9e8a397acf8b6f6f55a3fd5189eb72740ba.zip
add DynamicAccess utility
Diffstat (limited to 'kamon-core/src/main/scala/kamon/ReporterRegistry.scala')
-rw-r--r--kamon-core/src/main/scala/kamon/ReporterRegistry.scala41
1 files changed, 17 insertions, 24 deletions
diff --git a/kamon-core/src/main/scala/kamon/ReporterRegistry.scala b/kamon-core/src/main/scala/kamon/ReporterRegistry.scala
index 6c8622d4..ae43ca3c 100644
--- a/kamon-core/src/main/scala/kamon/ReporterRegistry.scala
+++ b/kamon-core/src/main/scala/kamon/ReporterRegistry.scala
@@ -22,7 +22,7 @@ import java.util.concurrent._
import com.typesafe.config.Config
import kamon.metric._
import kamon.trace.Span
-import kamon.util.Registration
+import kamon.util.{DynamicAccess, Registration}
import org.slf4j.LoggerFactory
import scala.concurrent.{ExecutionContext, ExecutionContextExecutorService, Future}
@@ -42,19 +42,17 @@ trait ReporterRegistry {
def stopAllReporters(): Future[Unit]
}
-trait MetricReporter {
+sealed trait Reporter {
def start(): Unit
def stop(): Unit
-
def reconfigure(config: Config): Unit
- def reportTickSnapshot(snapshot: TickSnapshot): Unit
}
-trait SpanReporter {
- def start(): Unit
- def stop(): Unit
+trait MetricReporter extends Reporter {
+ def reportTickSnapshot(snapshot: TickSnapshot): Unit
+}
- def reconfigure(config: Config): Unit
+trait SpanReporter extends Reporter {
def reportSpans(spans: Seq[Span.CompletedSpan]): Unit
}
@@ -77,22 +75,17 @@ class ReporterRegistryImpl(metrics: MetricsSnapshotGenerator, initialConfig: Con
logger.info("The kamon.reporters setting is empty, no reporters have been started.")
else {
registryConfiguration.configuredReporters.foreach { reporterFQCN =>
- Try {
- val reporterClass = Class.forName(reporterFQCN)
- val instance = reporterClass.newInstance()
- instance match {
- case mr: MetricReporter =>
- addMetricReporter(mr, "loaded-from-config: " + reporterFQCN)
- logger.info("Loaded metric reporter [{}]", reporterFQCN)
-
- case sr: SpanReporter =>
- addSpanReporter(sr, "loaded-from-config: " + reporterFQCN)
- logger.info("Loaded span reporter [{}]", reporterFQCN)
-
- case anyOther =>
- logger.error("Cannot add [{}] as a reporter, it doesn't implement the MetricReporter or SpanReporter interfaces", anyOther)
- }
- }.failed.foreach {
+ val dynamicAccess = new DynamicAccess(getClass.getClassLoader)
+ dynamicAccess.createInstanceFor[Reporter](reporterFQCN, Nil).map({
+ case mr: MetricReporter =>
+ addMetricReporter(mr, "loaded-from-config: " + reporterFQCN)
+ logger.info("Loaded metric reporter [{}]", reporterFQCN)
+
+ case sr: SpanReporter =>
+ addSpanReporter(sr, "loaded-from-config: " + reporterFQCN)
+ logger.info("Loaded span reporter [{}]", reporterFQCN)
+
+ }).failed.foreach {
t => logger.error(s"Failed to load configured reporter [$reporterFQCN]", t)
}
}