diff options
author | Diego <diegolparra@gmail.com> | 2015-04-28 00:31:57 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2015-04-28 00:31:57 -0300 |
commit | 74134d76363fb4a985b2b64b12d4d07d8006de54 (patch) | |
tree | 4695126eeced6fcf8a052540d61e2ac11a902fb0 /kamon-play/src/main/scala/kamon | |
parent | c6ba11c2238b85746ac525505b5dbc7e517eb9f9 (diff) | |
download | Kamon-74134d76363fb4a985b2b64b12d4d07d8006de54.tar.gz Kamon-74134d76363fb4a985b2b64b12d4d07d8006de54.tar.bz2 Kamon-74134d76363fb4a985b2b64b12d4d07d8006de54.zip |
! play: use SameThreadExecutionContext in Request and WS instrumentation in order to achieve more accurate metrics
Diffstat (limited to 'kamon-play/src/main/scala/kamon')
3 files changed, 6 insertions, 6 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/Play.scala b/kamon-play/src/main/scala/kamon/play/Play.scala index 270d244f..92f0dc74 100644 --- a/kamon-play/src/main/scala/kamon/play/Play.scala +++ b/kamon-play/src/main/scala/kamon/play/Play.scala @@ -38,7 +38,6 @@ class PlayExtension(private val system: ExtendedActorSystem) extends Kamon.Exten private val config = system.settings.config.getConfig("kamon.play") val httpServerMetrics = Kamon.metrics.entity(HttpServerMetrics, "play-server") - val defaultDispatcher = system.dispatcher val includeTraceToken: Boolean = config.getBoolean("automatic-trace-token-propagation") 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 ac73bff0..200fe135 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -19,6 +19,7 @@ import kamon.Kamon import kamon.play.Play import kamon.trace.TraceLocal.{ HttpContextKey, HttpContext } import kamon.trace._ +import kamon.util.SameThreadExecutionContext import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ import play.api.Routes @@ -36,6 +37,7 @@ class RequestInstrumentation { @Before("call(* play.api.GlobalSettings.onRouteRequest(..)) && args(requestHeader)") def beforeRouteRequest(requestHeader: RequestHeader): Unit = { import Kamon.tracer + val playExtension = Kamon(Play) val defaultTraceName = playExtension.generateTraceName(requestHeader) @@ -52,7 +54,6 @@ class RequestInstrumentation { val essentialAction = (requestHeader: RequestHeader) ⇒ { val playExtension = Kamon(Play) - val executor = playExtension.defaultDispatcher def onResult(result: Result): Result = { Tracer.currentContext.collect { ctx ⇒ @@ -72,8 +73,9 @@ class RequestInstrumentation { normaliseTraceName(requestHeader).map(Tracer.currentContext.rename) // Invoke the action - next(requestHeader).map(onResult)(executor) + next(requestHeader).map(onResult)(SameThreadExecutionContext) } + pjp.proceed(Array(EssentialAction(essentialAction))) } diff --git a/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala b/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala index db95047d..3a7c9563 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala @@ -19,10 +19,10 @@ package kamon.play.instrumentation import kamon.Kamon import kamon.play.Play import kamon.trace.{ Tracer, SegmentCategory } +import kamon.util.SameThreadExecutionContext import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation.{ Around, Aspect, Pointcut } import play.api.libs.ws.{ WSRequest, WSResponse } - import scala.concurrent.Future @Aspect @@ -35,12 +35,11 @@ class WSInstrumentation { def aroundExecuteRequest(pjp: ProceedingJoinPoint, request: WSRequest): Any = { Tracer.currentContext.collect { ctx ⇒ val playExtension = Kamon(Play) - val executor = playExtension.defaultDispatcher val segmentName = playExtension.generateHttpClientSegmentName(request) val segment = ctx.startSegment(segmentName, SegmentCategory.HttpClient, Play.SegmentLibraryName) val response = pjp.proceed().asInstanceOf[Future[WSResponse]] - response.map(result ⇒ segment.finish())(executor) + response.map(result ⇒ segment.finish())(SameThreadExecutionContext) response } getOrElse pjp.proceed() } |