aboutsummaryrefslogtreecommitdiff
path: root/kamon-play
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2015-03-05 23:39:44 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2015-03-09 23:09:08 +0100
commit959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b (patch)
tree27c1fe8f22429fe3820f988ab17caaf8e4a6fa3a /kamon-play
parent69ea63923e0d3697f8ca4c7eb9cb808821832aa2 (diff)
downloadKamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.gz
Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.tar.bz2
Kamon-959ce3573253ec4ac5b837d8a9c9e70f1f80bd6b.zip
! all: introduced support for metric tags.
Diffstat (limited to 'kamon-play')
-rw-r--r--kamon-play/src/main/scala/kamon/play/Play.scala8
-rw-r--r--kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala38
2 files changed, 25 insertions, 21 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/Play.scala b/kamon-play/src/main/scala/kamon/play/Play.scala
index 9e160d58..270d244f 100644
--- a/kamon-play/src/main/scala/kamon/play/Play.scala
+++ b/kamon-play/src/main/scala/kamon/play/Play.scala
@@ -36,13 +36,7 @@ class PlayExtension(private val system: ExtendedActorSystem) extends Kamon.Exten
log.info(s"Starting the Kamon(Play) extension")
private val config = system.settings.config.getConfig("kamon.play")
- val httpServerMetrics = {
- val metricsExtension = Kamon.metrics
- val factory = metricsExtension.instrumentFactory(HttpServerMetrics.category)
- val entity = Entity("play-server", HttpServerMetrics.category)
-
- metricsExtension.register(entity, new HttpServerMetrics(factory)).recorder
- }
+ val httpServerMetrics = Kamon.metrics.entity(HttpServerMetrics, "play-server")
val defaultDispatcher = system.dispatcher
val includeTraceToken: Boolean = config.getBoolean("automatic-trace-token-propagation")
diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
index d639fd9f..fe16ccbf 100644
--- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
+++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
@@ -17,7 +17,7 @@
package kamon.play
import kamon.Kamon
-import kamon.metric.{ EntitySnapshot, TraceMetrics }
+import kamon.metric.{ Entity, EntitySnapshot, TraceMetrics }
import kamon.trace.{ Tracer, TraceContext, SegmentCategory }
import org.scalatest.{ Matchers, WordSpecLike }
import org.scalatestplus.play.OneServerPerSuite
@@ -32,7 +32,7 @@ import scala.concurrent.duration._
class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPerSuite {
Kamon.start()
- import kamon.metric.TraceMetricsSpec.SegmentSyntax
+
System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf")
override lazy val port: Port = 19003
@@ -46,10 +46,16 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer
"propagate the TraceContext inside an Action and complete the WS request" in {
Await.result(route(FakeRequest(GET, "/inside")).get, 10 seconds)
- val snapshot = takeSnapshotOf("GET: /inside")
+ val snapshot = takeSnapshotOf("GET: /inside", "trace")
snapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- snapshot.segments.size should be(1)
- snapshot.segment(s"http://localhost:$port/async", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1)
+
+ val segmentMetricsSnapshot = takeSnapshotOf(s"http://localhost:$port/async", "trace-segment",
+ tags = Map(
+ "trace" -> "GET: /inside",
+ "category" -> SegmentCategory.HttpClient,
+ "library" -> Play.SegmentLibraryName))
+
+ segmentMetricsSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
}
"propagate the TraceContext outside an Action and complete the WS request" in {
@@ -58,22 +64,26 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer
Tracer.currentContext.finish()
}
- val snapshot = takeSnapshotOf("trace-outside-action")
+ val snapshot = takeSnapshotOf("trace-outside-action", "trace")
snapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
- snapshot.segments.size should be(1)
- snapshot.segment(s"http://localhost:$port/outside", SegmentCategory.HttpClient, Play.SegmentLibraryName).numberOfMeasurements should be(1)
- }
+ val segmentMetricsSnapshot = takeSnapshotOf(s"http://localhost:$port/outside", "trace-segment",
+ tags = Map(
+ "trace" -> "trace-outside-action",
+ "category" -> SegmentCategory.HttpClient,
+ "library" -> Play.SegmentLibraryName))
+
+ segmentMetricsSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1)
+ }
}
+ lazy val collectionContext = Kamon.metrics.buildDefaultCollectionContext
+
def newContext(name: String): TraceContext =
Kamon.tracer.newContext(name)
- def takeSnapshotOf(traceName: String): EntitySnapshot = {
- // Give some time for async segments to finish.
- Thread.sleep(300)
- val recorder = Kamon.metrics.register(TraceMetrics, traceName).get.recorder
- val collectionContext = Kamon.metrics.buildDefaultCollectionContext
+ def takeSnapshotOf(name: String, category: String, tags: Map[String, String] = Map.empty): EntitySnapshot = {
+ val recorder = Kamon.metrics.find(Entity(name, category, tags)).get
recorder.collect(collectionContext)
}