aboutsummaryrefslogtreecommitdiff
path: root/kamon-spray
diff options
context:
space:
mode:
authorIvan Topolnak <ivantopo@gmail.com>2013-11-07 18:41:33 -0300
committerIvan Topolnak <ivantopo@gmail.com>2013-11-07 18:41:33 -0300
commitbf86900669d649308f4914c54e6fe076510506a6 (patch)
treed8bf9af9f5c8a946d757137a303f6956c05edb03 /kamon-spray
parent2b63540e5fffab545d0846cfb3dab5c0e1d0c9e1 (diff)
downloadKamon-bf86900669d649308f4914c54e6fe076510506a6.tar.gz
Kamon-bf86900669d649308f4914c54e6fe076510506a6.tar.bz2
Kamon-bf86900669d649308f4914c54e6fe076510506a6.zip
halfway to our own NewRelic Agent
Diffstat (limited to 'kamon-spray')
-rw-r--r--kamon-spray/src/main/scala/spray/can/server/ServerRequestTracing.scala3
-rw-r--r--kamon-spray/src/test/scala/kamon/ServerRequestTracingSpec.scala66
2 files changed, 50 insertions, 19 deletions
diff --git a/kamon-spray/src/main/scala/spray/can/server/ServerRequestTracing.scala b/kamon-spray/src/main/scala/spray/can/server/ServerRequestTracing.scala
index d5e21f35..8055cf6b 100644
--- a/kamon-spray/src/main/scala/spray/can/server/ServerRequestTracing.scala
+++ b/kamon-spray/src/main/scala/spray/can/server/ServerRequestTracing.scala
@@ -42,8 +42,9 @@ class ServerRequestTracing {
publishWarning(s"Different ids when trying to close a Trace, original: [$original] - incoming: [$incoming]")
case Some(_) => // nothing to do here.
-
+
case None =>
+ original.finish
publishWarning(s"Trace context not present while closing the Trace: [$original]")
}
}
diff --git a/kamon-spray/src/test/scala/kamon/ServerRequestTracingSpec.scala b/kamon-spray/src/test/scala/kamon/ServerRequestTracingSpec.scala
index 4cff38be..d789042e 100644
--- a/kamon-spray/src/test/scala/kamon/ServerRequestTracingSpec.scala
+++ b/kamon-spray/src/test/scala/kamon/ServerRequestTracingSpec.scala
@@ -13,37 +13,67 @@ import kamon.trace.Trace
import kamon.Kamon.Extension
import kamon.trace.UowTracing.{Finish, Start}
-class ServerRequestTracingSpec extends TestKit(ActorSystem("server-request-tracing-spec")) with WordSpecLike with RequestBuilding {
+class ServerRequestTracingSpec extends TestKit(ActorSystem("server-request-tracing-spec")) with WordSpecLike with RequestBuilding with TestServer {
"the spray server request tracing instrumentation" should {
- "start tracing a request when entering the server and close it when responding" in new TestServer {
- client(Get(s"http://127.0.0.1:$port/"))
+ "trace a request start/finish sequence when proper TraceContext is received" in {
+ send {
+ Get(s"http://127.0.0.1:$port/ok")
+ }
within(5 seconds) {
- val traceId = expectMsgPF() { case Start(id) => id}
+ val traceId = expectMsgPF() { case Start(id, _) => id}
expectMsgPF() { case Finish(traceId) => }
}
}
- }
+ "finish a request even if no TraceContext is received in the response" in {
+ send {
+ Get(s"http://127.0.0.1:$port/clearcontext")
+ }
+ within(5 seconds) {
+ val traceId = expectMsgPF() { case Start(id, _) => id}
+ expectMsgPF() { case Finish(traceId) => }
+ }
+ }
- trait TestServer extends SimpleRoutingApp {
+ "give a initial transaction name using the method and path from the request" in {
+ send {
+ Get(s"http://127.0.0.1:$port/accounts")
+ }
- // Nasty, but very helpful for tests.
- AkkaExtensionSwap.swap(system, Trace, new Extension {
- def manager: ActorRef = testActor
- })
+ within(5 seconds) {
+ expectMsgPF() { case Start(_, "GET: /accounts") => }
+ }
+ }
+ }
+}
- implicit val timeout = Timeout(20 seconds)
- val port: Int = Await.result(
- startServer(interface = "127.0.0.1", port = 0)(
- get {
- complete("ok")
+trait TestServer extends SimpleRoutingApp {
+ self: TestKit =>
+
+ // Nasty, but very helpful for tests.
+ AkkaExtensionSwap.swap(system, Trace, new Extension {
+ def manager: ActorRef = testActor
+ })
+
+ implicit val timeout = Timeout(20 seconds)
+ val port: Int = Await.result(
+ startServer(interface = "127.0.0.1", port = 0)(
+ get {
+ path("ok") {
+ complete("ok")
+ } ~
+ path("clearcontext"){
+ complete {
+ Trace.clear
+ "ok"
+ }
}
- ), timeout.duration).localAddress.getPort
+ }
+ ), timeout.duration).localAddress.getPort
- val client = sendReceive(system, system.dispatcher, timeout)
+ val send = sendReceive(system, system.dispatcher, timeout)
- }
}