From 04550ce1daff2b3d13aa85931686a303bf93fbd8 Mon Sep 17 00:00:00 2001 From: Diego Date: Sun, 9 Mar 2014 15:01:51 -0300 Subject: Play Integration with: X-Trace-Token, WebExternal Time and Error publishing in Akka EventStream --- .../instrumentation/RequestInstrumentation.scala | 22 +++++++++++++++++++--- .../play/instrumentation/WSInstrumentation.scala | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) (limited to 'kamon-play/src/main/scala/kamon/play/instrumentation') 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 c55f89e0..18060895 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -1,5 +1,5 @@ /* =================================================== - * Copyright © 2013 2014 the kamon project + * Copyright © 2013-2014 the kamon project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package kamon.play.instrumentation +import scala.concurrent.ExecutionContext.Implicits.global import kamon.trace.{ TraceRecorder, TraceContextAware } import kamon.Kamon import kamon.play.Play @@ -25,12 +26,11 @@ import akka.actor.ActorSystem import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation._ import scala.Some -import scala.concurrent.ExecutionContext.Implicits.global @Aspect class RequestInstrumentation { - @DeclareMixin("play.api.mvc.RequestHeader || play.api.test.FakeRequest") + @DeclareMixin("play.api.mvc.RequestHeader") def mixinContextAwareNewRequest: TraceContextAware = TraceContextAware.default @Pointcut("execution(* play.api.GlobalSettings+.onStart(*)) && args(application)") @@ -49,6 +49,22 @@ class RequestInstrumentation { Filters(pjp.proceed(Array(next)).asInstanceOf[EssentialAction], kamonRequestFilter) } + @Pointcut("execution(* play.api.GlobalSettings+.onError(..)) && args(request, ex)") + def onError(request: TraceContextAware, ex: Throwable): Unit = {} + + @Around("onError(request, ex)") + def aroundOnError(pjp: ProceedingJoinPoint, request: TraceContextAware, ex: Throwable): Any = { + val simpleResult = request.traceContext match { + case None ⇒ pjp.proceed() + case Some(ctx) ⇒ { + val actorSystem = ctx.system + Kamon(Play)(actorSystem).publishErrorMessage(actorSystem, ex.getMessage, ex) + pjp.proceed() + } + } + simpleResult + } + private[this] val kamonRequestFilter = Filter { (nextFilter, requestHeader) ⇒ processRequest(requestHeader) 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 2fedcd70..498afc4d 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala @@ -1,3 +1,19 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + package kamon.play.instrumentation import javax.net.ssl.SSLContext -- cgit v1.2.3