diff options
author | João Ferreira <jtjeferreira@gmail.com> | 2015-05-21 20:56:42 +0100 |
---|---|---|
committer | João Ferreira <jtjeferreira@gmail.com> | 2015-05-22 11:08:02 +0100 |
commit | b927d1440f793bce669c8dc5b796f333cbd8abe6 (patch) | |
tree | 1d677ea1b30eed26796ebb634ea892e12dbf82df /kamon-spray/src/test/scala/kamon/spray | |
parent | f47cc5d6ff8e08599156c731db8a8335f6df3ada (diff) | |
download | Kamon-b927d1440f793bce669c8dc5b796f333cbd8abe6.tar.gz Kamon-b927d1440f793bce669c8dc5b796f333cbd8abe6.tar.bz2 Kamon-b927d1440f793bce669c8dc5b796f333cbd8abe6.zip |
= spray: Fix segment finishing on errors
Diffstat (limited to 'kamon-spray/src/test/scala/kamon/spray')
-rw-r--r-- | kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala b/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala index b66d54c3..2279469c 100644 --- a/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala +++ b/kamon-spray/src/test/scala/kamon/spray/ClientRequestInstrumentationSpec.scala @@ -17,6 +17,7 @@ package kamon.spray import akka.testkit.TestProbe +import akka.actor.Status import kamon.testkit.BaseKamonSpec import org.scalatest.concurrent.ScalaFutures import org.scalatest.time.{ Millis, Seconds, Span } @@ -138,6 +139,41 @@ class ClientRequestInstrumentationSpec extends BaseKamonSpec("client-request-ins segmentMetricsSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1) } + "start and finish a segment in case of error" in { + enableAutomaticTraceTokenPropagation() + enablePipeliningSegmentCollectionStrategy() + + val transport = TestProbe() + val (_, _, bound) = buildSHostConnectorAndServer + + // Initiate a request within the context of a trace + val (testContext, responseFuture) = Tracer.withContext(newContext("assign-name-to-segment-with-request-level-api")) { + val rF = sendReceive(transport.ref)(ec, 10.seconds) { + Get(s"http://${bound.localAddress.getHostName}:${bound.localAddress.getPort}/request-level-api-segment") + } + + (Tracer.currentContext, rF) + } + + // Receive the request and reply back + transport.expectMsgType[HttpRequest] + transport.reply(Status.Failure(new Exception("An Error Ocurred"))) + responseFuture.failed.futureValue.getMessage() should be("An Error Ocurred") + + testContext.finish() + + val traceMetricsSnapshot = takeSnapshotOf("assign-name-to-segment-with-request-level-api", "trace") + traceMetricsSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1) + + val segmentMetricsSnapshot = takeSnapshotOf("request-level /request-level-api-segment", "trace-segment", + tags = Map( + "trace" -> "assign-name-to-segment-with-request-level-api", + "category" -> SegmentCategory.HttpClient, + "library" -> Spray.SegmentLibraryName)) + + segmentMetricsSnapshot.histogram("elapsed-time").get.numberOfMeasurements should be(1) + } + "rename a request level api segment once it reaches the relevant host connector" in { enableAutomaticTraceTokenPropagation() enablePipeliningSegmentCollectionStrategy() |