aboutsummaryrefslogtreecommitdiff
path: root/kamon-play
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2014-03-09 15:01:51 -0300
committerDiego <diegolparra@gmail.com>2014-03-09 15:01:51 -0300
commit04550ce1daff2b3d13aa85931686a303bf93fbd8 (patch)
treea9be0d45072915d4f3c10e7cdc50052f7ef7d445 /kamon-play
parentb8a26e0f173a528c700a3d0cfa4ed2f8079a7ae1 (diff)
downloadKamon-04550ce1daff2b3d13aa85931686a303bf93fbd8.tar.gz
Kamon-04550ce1daff2b3d13aa85931686a303bf93fbd8.tar.bz2
Kamon-04550ce1daff2b3d13aa85931686a303bf93fbd8.zip
Play Integration with: X-Trace-Token, WebExternal Time and Error publishing in Akka EventStream
Diffstat (limited to 'kamon-play')
-rw-r--r--kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala22
-rw-r--r--kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala16
-rw-r--r--kamon-play/src/test/resources/META-INF/aop.xml11
-rw-r--r--kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala14
-rw-r--r--kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala16
-rw-r--r--kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala26
6 files changed, 85 insertions, 20 deletions
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 <http://kamon.io/>
+ * 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.
@@ -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 <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 javax.net.ssl.SSLContext
diff --git a/kamon-play/src/test/resources/META-INF/aop.xml b/kamon-play/src/test/resources/META-INF/aop.xml
new file mode 100644
index 00000000..63cbe8a9
--- /dev/null
+++ b/kamon-play/src/test/resources/META-INF/aop.xml
@@ -0,0 +1,11 @@
+<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
+
+<aspectj>
+ <aspects>
+ <aspect name="kamon.play.instrumentation.FakeRequestIntrumentation"/>
+ </aspects>
+
+ <weaver options="-verbose -showWeaveInfo">
+ <include within="play.api..*"/>
+ </weaver>
+</aspectj>
diff --git a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala
index 2dce39f8..0c4ac57b 100644
--- a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala
+++ b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala
@@ -1,5 +1,5 @@
/* ===================================================
- * Copyright © 2013 2014 the kamon project <http://kamon.io/>
+ * 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.
@@ -73,7 +73,7 @@ class RequestInstrumentationSpec extends PlaySpecification {
private val traceTokenValue = "kamon-trace-token-test"
private val traceTokenHeaderName = "X-Trace-Token"
private val expectedToken = Some(traceTokenValue)
- private val traceTokenHeader = (traceTokenHeaderName -> traceTokenValue)
+ private val traceTokenHeader = traceTokenHeaderName -> traceTokenValue
"the Request instrumentation" should {
"respond to the asyncResult action with X-Trace-Token" in new WithServer(appWithRoutes) {
@@ -81,28 +81,28 @@ class RequestInstrumentationSpec extends PlaySpecification {
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
- "respond to the async action with X-Trace-Token" in new WithServer(appWithRoutes) {
+ "respond to the Async Action with X-Trace-Token" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/async").withHeaders(traceTokenHeader))
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
- "respond to the notFound action with X-Trace-Token" in new WithServer(appWithRoutes) {
+ "respond to the NotFound Action with X-Trace-Token" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/notFound").withHeaders(traceTokenHeader))
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
- "respond to the default action with X-Trace-Token" in new WithServer(appWithRoutes) {
+ "respond to the Default Action with X-Trace-Token" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/default").withHeaders(traceTokenHeader))
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
- "respond to the redirect action with X-Trace-Token" in new WithServer(appWithRoutes) {
+ "respond to the Redirect Action with X-Trace-Token" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/redirect").withHeaders(traceTokenHeader))
header("Location", result) must equalTo(Some("/redirected"))
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
- "respond to the async action with X-Trace-Token and the renamed trace" in new WithServer(appWithRoutes) {
+ "respond to the Async Action with X-Trace-Token and the renamed trace" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/async-renamed").withHeaders(traceTokenHeader))
header(traceTokenHeaderName, result) must equalTo(expectedToken)
}
diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
index 2cebfe42..3b8a5492 100644
--- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
+++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala
@@ -17,25 +17,22 @@
package kamon.play
import play.api.test._
-import play.api.mvc.{ Results, Action }
+import play.api.mvc.Action
import play.api.mvc.Results.Ok
import scala.Some
import scala.concurrent.ExecutionContext.Implicits.global
-import scala.concurrent.Future
import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner
-import play.api.mvc.AsyncResult
import play.api.test.FakeApplication
-import kamon.play.action.TraceName
import play.api.libs.ws.WS
+import scala.util._
@RunWith(classOf[JUnitRunner])
class WSInstrumentationSpec extends PlaySpecification {
System.setProperty("config.file", "./kamon-play/src/test/resources/conf/application.conf")
val appWithRoutes = FakeApplication(withRoutes = {
-
case ("GET", "/async") ⇒
Action.async {
WS.url("http://www.google.com").get().map {
@@ -46,14 +43,13 @@ class WSInstrumentationSpec extends PlaySpecification {
})
"the WS instrumentation" should {
- "respond to the async action" in new WithServer(appWithRoutes) {
+ "respond to the Async Action and complete the WS request" in new WithServer(appWithRoutes) {
val Some(result) = route(FakeRequest(GET, "/async"))
- println("-902425309-53095-5 " + result)
result.onComplete {
- case scala.util.Success(r) ⇒ println(r)
- case scala.util.Failure(t) ⇒ println(t)
+ case Success(result) ⇒ result.header.status must equalTo(200)
+ case Failure(throwable) ⇒ failure(throwable.getMessage)
}
- Thread.sleep(3000)
+ Thread.sleep(2000) //wait to complete the future
}
}
} \ No newline at end of file
diff --git a/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala b/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala
new file mode 100644
index 00000000..55b72908
--- /dev/null
+++ b/kamon-play/src/test/scala/kamon/play/instrumentation/FakeRequestIntrumentation.scala
@@ -0,0 +1,26 @@
+/* ===================================================
+ * 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 org.aspectj.lang.annotation.{ DeclareMixin, Aspect }
+import kamon.trace.TraceContextAware
+
+@Aspect
+class FakeRequestIntrumentation {
+ @DeclareMixin("play.api.test.FakeRequest")
+ def mixinContextAwareNewRequest: TraceContextAware = TraceContextAware.default
+}