diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-23 15:08:59 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-23 15:08:59 -0300 |
commit | 63f99d1f5cc7850fc7c559385b85fa1828d7cd79 (patch) | |
tree | ec38ed5146eedddd455d8525e7f9fa10679b8190 /kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala | |
parent | 78badb3090a07fe6447255b6d3d690f0f8569feb (diff) | |
download | Kamon-63f99d1f5cc7850fc7c559385b85fa1828d7cd79.tar.gz Kamon-63f99d1f5cc7850fc7c559385b85fa1828d7cd79.tar.bz2 Kamon-63f99d1f5cc7850fc7c559385b85fa1828d7cd79.zip |
+ core,spray: create and implement http server metrics for spray, related to #56
Diffstat (limited to 'kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala')
-rw-r--r-- | kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala b/kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala index 85782e22..69b0160e 100644 --- a/kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala +++ b/kamon-spray/src/main/scala/spray/can/server/ServerRequestInstrumentation.scala @@ -22,7 +22,7 @@ import spray.http.{ HttpResponse, HttpMessagePartWrapper, HttpRequest } import akka.event.Logging.Warning import scala.Some import kamon.Kamon -import kamon.spray.Spray +import kamon.spray.{ SprayExtension, Spray } import org.aspectj.lang.ProceedingJoinPoint import spray.http.HttpHeaders.RawHeader @@ -68,20 +68,21 @@ class ServerRequestInstrumentation { val storedContext = openRequest.traceContext verifyTraceContextConsistency(incomingContext, storedContext) - val proceedResult = incomingContext match { + incomingContext match { case None ⇒ pjp.proceed() case Some(traceContext) ⇒ val sprayExtension = Kamon(Spray)(traceContext.system) - if (sprayExtension.includeTraceToken) { + val proceedResult = if (sprayExtension.includeTraceToken) { val responseWithHeader = includeTraceTokenIfPossible(response, sprayExtension.traceTokenHeaderName, traceContext.token) pjp.proceed(Array(openRequest, responseWithHeader)) } else pjp.proceed - } - TraceRecorder.finish() - proceedResult + TraceRecorder.finish() + recordHttpServerMetrics(response, traceContext.name, sprayExtension) + proceedResult + } } def verifyTraceContextConsistency(incomingTraceContext: Option[TraceContext], storedTraceContext: Option[TraceContext]): Unit = { @@ -102,6 +103,12 @@ class ServerRequestInstrumentation { } + def recordHttpServerMetrics(response: HttpMessagePartWrapper, traceName: String, sprayExtension: SprayExtension): Unit = + response match { + case httpResponse: HttpResponse ⇒ sprayExtension.httpServerMetrics.recordResponse(traceName, httpResponse.status.intValue.toString) + case other ⇒ // Nothing to do then. + } + def includeTraceTokenIfPossible(response: HttpMessagePartWrapper, traceTokenHeaderName: String, token: String): HttpMessagePartWrapper = response match { case response: HttpResponse ⇒ response.withHeaders(response.headers ::: RawHeader(traceTokenHeaderName, token) :: Nil) |