aboutsummaryrefslogtreecommitdiff
path: root/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2015-06-11 08:42:58 -0300
committerDiego <diegolparra@gmail.com>2015-08-09 21:03:23 -0300
commit018e30868ccbbdcaa9ecae2840143218444eddc3 (patch)
tree4bc4d2457e073769a7bd1ad562b61fe0f12e3f27 /kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation
parentd4c063e790af5bc0a58dea7f04fd2df59b3414f1 (diff)
downloadKamon-018e30868ccbbdcaa9ecae2840143218444eddc3.tar.gz
Kamon-018e30868ccbbdcaa9ecae2840143218444eddc3.tar.bz2
Kamon-018e30868ccbbdcaa9ecae2840143218444eddc3.zip
! play: starting play 2.4.x integration
Diffstat (limited to 'kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation')
-rw-r--r--kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala42
-rw-r--r--kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala110
-rw-r--r--kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala46
3 files changed, 0 insertions, 198 deletions
diff --git a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala b/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala
deleted file mode 100644
index 3c79fae4..00000000
--- a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/LoggerLikeInstrumentation.scala
+++ /dev/null
@@ -1,42 +0,0 @@
-/* =========================================================================================
- * Copyright © 2013-2014 the kamon project <http://kamon.io/>
- *
- * 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 kamon.trace.logging.MdcKeysSupport
-import org.aspectj.lang.ProceedingJoinPoint
-import org.aspectj.lang.annotation._
-
-@Aspect
-class LoggerLikeInstrumentation extends MdcKeysSupport {
-
- @Pointcut("execution(* play.api.LoggerLike+.info(..))")
- def infoPointcut(): Unit = {}
-
- @Pointcut("execution(* play.api.LoggerLike+.warn(..))")
- def warnPointcut(): Unit = {}
-
- @Pointcut("execution(* play.api.LoggerLike+.error(..))")
- def errorPointcut(): Unit = {}
-
- @Pointcut("execution(* play.api.LoggerLike+.trace(..))")
- def tracePointcut(): Unit = {}
-
- @Around("(infoPointcut() || warnPointcut() || errorPointcut() || tracePointcut())")
- def aroundLog(pjp: ProceedingJoinPoint): Any = withMdc {
- pjp.proceed()
- }
-}
-
diff --git a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala b/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala
deleted file mode 100644
index 9b47d5bb..00000000
--- a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala
+++ /dev/null
@@ -1,110 +0,0 @@
-/* =========================================================================================
- * Copyright © 2013-2015 the kamon project <http://kamon.io/>
- *
- * 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 kamon.Kamon
-import kamon.play.Play
-import kamon.trace.TraceLocal.{ HttpContext, HttpContextKey }
-import kamon.trace._
-import kamon.util.SameThreadExecutionContext
-import org.aspectj.lang.ProceedingJoinPoint
-import org.aspectj.lang.annotation._
-import play.api.mvc.Results._
-import play.api.mvc._
-
-@Aspect
-class RequestInstrumentation {
-
- import RequestInstrumentation._
-
- @DeclareMixin("play.api.mvc.RequestHeader+")
- def mixinContextAwareNewRequest: TraceContextAware = TraceContextAware.default
-
- @Before("call(* play.api.http.DefaultHttpRequestHandler.routeRequest(..)) && args(requestHeader)")
- def beforeRouteRequest(requestHeader: RequestHeader): Unit = {
- import Kamon.tracer
-
- val playExtension = Kamon(Play)
-
- val token = if (playExtension.includeTraceToken) {
- requestHeader.headers.get(playExtension.traceTokenHeaderName)
- } else None
-
- Tracer.setCurrentContext(tracer.newContext("UnnamedTrace", token))
- }
-
- @Around("call(* play.api.http.HttpFilters.filters(..))")
- def aroundFilters(pjp: ProceedingJoinPoint): Any = {
- val filter = new EssentialFilter {
- override def apply(next: EssentialAction): EssentialAction = {
- val essentialAction = (requestHeader: RequestHeader) ⇒ {
-
- val playExtension = Kamon(Play)
-
- def onResult(result: Result): Result = {
- Tracer.currentContext.collect { ctx ⇒
- ctx.finish()
-
- httpServerMetrics.recordResponse(ctx.name, result.header.status.toString)
-
- if (playExtension.includeTraceToken) result.withHeaders(playExtension.traceTokenHeaderName -> ctx.token)
- else result
-
- } getOrElse result
- }
- //store in TraceLocal useful data to diagnose errors
- storeDiagnosticData(requestHeader)
-
- //override the current trace name
- Tracer.currentContext.rename(playExtension.generateTraceName(requestHeader))
-
- // Invoke the action
- next(requestHeader).map(onResult)(SameThreadExecutionContext)
- }
- EssentialAction(essentialAction)
- }
- }
- pjp.proceed().asInstanceOf[Seq[EssentialFilter]] :+ filter
- }
-
- @Before("call(* play.api.http.HttpErrorHandler.onClientServerError(..)) && args(requestContextAware, statusCode, *)")
- def beforeOnClientError(requestContextAware: TraceContextAware, statusCode: Int): Unit = {
- requestContextAware.traceContext.collect { ctx ⇒
- httpServerMetrics.recordResponse(ctx.name, statusCode.toString)
- }
- }
-
- @Before("call(* play.api.http.HttpErrorHandler.onServerError(..)) && args(requestContextAware, ex)")
- def beforeOnServerError(requestContextAware: TraceContextAware, ex: Throwable): Unit = {
- requestContextAware.traceContext.collect { ctx ⇒
- httpServerMetrics.recordResponse(ctx.name, InternalServerError.header.status.toString)
- }
- }
-
- def storeDiagnosticData(request: RequestHeader): Unit = {
- val agent = request.headers.get(UserAgent).getOrElse(Unknown)
- val forwarded = request.headers.get(XForwardedFor).getOrElse(Unknown)
-
- TraceLocal.store(HttpContextKey)(HttpContext(agent, request.uri, forwarded))
- }
-}
-
-object RequestInstrumentation {
- val UserAgent = "User-Agent"
- val XForwardedFor = "X-Forwarded-For"
- val Unknown = "unknown"
- val httpServerMetrics = Kamon(Play).httpServerMetrics
-}
diff --git a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala b/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala
deleted file mode 100644
index 66c933f6..00000000
--- a/kamon-play-2.4.x/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala
+++ /dev/null
@@ -1,46 +0,0 @@
-/* ===================================================
- * Copyright © 2013-2014 the kamon project <http://kamon.io/>
- *
- * 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 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
-class WSInstrumentation {
-
- @Pointcut("execution(* play.api.libs.ws.ning.NingWSRequest.execute()) && this(request)")
- def onExecuteRequest(request: WSRequest): Unit = {}
-
- @Around("onExecuteRequest(request)")
- def aroundExecuteRequest(pjp: ProceedingJoinPoint, request: WSRequest): Any = {
- Tracer.currentContext.collect { ctx ⇒
- val playExtension = Kamon(Play)
- val segmentName = playExtension.generateHttpClientSegmentName(request)
- val segment = ctx.startSegment(segmentName, SegmentCategory.HttpClient, Play.SegmentLibraryName)
- val response = pjp.proceed().asInstanceOf[Future[WSResponse]]
-
- response.onComplete(result ⇒ segment.finish())(SameThreadExecutionContext)
- response
- } getOrElse pjp.proceed()
- }
-} \ No newline at end of file