diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-27 17:03:10 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-27 17:03:10 -0300 |
commit | 023cc7a93e92524d1829256677cfbff1056fbe6f (patch) | |
tree | 246f185f10d2acc60b30d847dbb88ef5158c28f0 /kamon-play/src/main/scala/kamon/play | |
parent | f366ce56f60e8df06f943fe48a861c7883bb606f (diff) | |
download | Kamon-023cc7a93e92524d1829256677cfbff1056fbe6f.tar.gz Kamon-023cc7a93e92524d1829256677cfbff1056fbe6f.tar.bz2 Kamon-023cc7a93e92524d1829256677cfbff1056fbe6f.zip |
+ play: record http server metrics, closes #56
Diffstat (limited to 'kamon-play/src/main/scala/kamon/play')
-rw-r--r-- | kamon-play/src/main/scala/kamon/play/Play.scala | 3 | ||||
-rw-r--r-- | kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/Play.scala b/kamon-play/src/main/scala/kamon/play/Play.scala index ca9c10e5..03436458 100644 --- a/kamon-play/src/main/scala/kamon/play/Play.scala +++ b/kamon-play/src/main/scala/kamon/play/Play.scala @@ -18,6 +18,8 @@ package kamon.play import akka.actor.{ ExtendedActorSystem, Extension, ExtensionIdProvider, ExtensionId } import kamon.Kamon +import kamon.http.HttpServerMetrics +import kamon.metric.Metrics object Play extends ExtensionId[PlayExtension] with ExtensionIdProvider { override def lookup(): ExtensionId[_ <: Extension] = Play @@ -29,6 +31,7 @@ class PlayExtension(private val system: ExtendedActorSystem) extends Kamon.Exten private val config = system.settings.config.getConfig("kamon.play") + val httpServerMetrics = Kamon(Metrics)(system).register(HttpServerMetrics, HttpServerMetrics.Factory).get val defaultDispatcher = system.dispatchers.lookup(config.getString("dispatcher")) val includeTraceToken: Boolean = config.getBoolean("include-trace-token-header") val traceTokenHeaderName: String = config.getString("trace-token-header-name") diff --git a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala index db864fb6..975510e9 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -16,7 +16,7 @@ package kamon.play.instrumentation import kamon.Kamon -import kamon.play.Play +import kamon.play.{ PlayExtension, Play } import kamon.trace.{ TraceContextAware, TraceRecorder } import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ @@ -52,11 +52,17 @@ class RequestInstrumentation { val essentialAction = (requestHeader: RequestHeader) ⇒ { val incomingContext = TraceRecorder.currentContext - val executor = Kamon(Play)(Akka.system()).defaultDispatcher + val playExtension = Kamon(Play)(Akka.system()) + val executor = playExtension.defaultDispatcher next(requestHeader).map { result ⇒ + TraceRecorder.currentContext.map { ctx ⇒ + recordHttpServerMetrics(result, ctx.name, playExtension) + } + TraceRecorder.finish() + incomingContext match { case None ⇒ result case Some(traceContext) ⇒ @@ -70,6 +76,9 @@ class RequestInstrumentation { pjp.proceed(Array(EssentialAction(essentialAction))) } + def recordHttpServerMetrics(result: Result, traceName: String, playExtension: PlayExtension): Unit = + playExtension.httpServerMetrics.recordResponse(traceName, result.header.status.toString, 1L) + @Around("execution(* play.api.GlobalSettings+.onError(..)) && args(request, ex)") def aroundOnError(pjp: ProceedingJoinPoint, request: TraceContextAware, ex: Throwable): Any = request.traceContext match { case None ⇒ pjp.proceed() |