diff options
author | Diego <diegolparra@gmail.com> | 2015-08-10 00:07:46 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2015-08-10 00:07:46 -0300 |
commit | 59b42603019ce522f1642c93cd1342ddc64f9bf2 (patch) | |
tree | f1e4c0cfddd1b43c24a9fc9c49e30b464af27921 /kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala | |
parent | c80f51c7bb98c1a42c04df11ba40cd301018c839 (diff) | |
download | Kamon-59b42603019ce522f1642c93cd1342ddc64f9bf2.tar.gz Kamon-59b42603019ce522f1642c93cd1342ddc64f9bf2.tar.bz2 Kamon-59b42603019ce522f1642c93cd1342ddc64f9bf2.zip |
! play-2.4.x: grouping traces that doesn't are tagged as UntaggedTraces in order to avoid the creation of undesired traces
Diffstat (limited to 'kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala')
-rw-r--r-- | kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala b/kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala index 02a1fcc3..c30d0529 100644 --- a/kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala +++ b/kamon-play-2.4.x/src/test/scala/kamon/play/RequestInstrumentationSpec.scala @@ -25,7 +25,7 @@ import org.scalatestplus.play._ import play.api.DefaultGlobal import play.api.http.{ HttpErrorHandler, HttpFilters, Writeable } import play.api.libs.concurrent.Execution.Implicits.defaultContext -import play.api.libs.ws.WS +import play.api.libs.ws.{ WSRequest, WS } import play.api.mvc.Results.Ok import play.api.mvc._ import play.api.routing.SimpleRouter @@ -257,4 +257,32 @@ object controllers { Ok("invoked show with: " + id) } } +} + +class TestNameGenerator extends NameGenerator { + import scala.collection.concurrent.TrieMap + import play.api.routing.Router + import java.util.Locale + import kamon.util.TriemapAtomicGetOrElseUpdate.Syntax + + private val cache = TrieMap.empty[String, String] + private val normalizePattern = """\$([^<]+)<[^>]+>""".r + + def generateTraceName(requestHeader: RequestHeader): String = requestHeader.tags.get(Router.Tags.RouteVerb).map { verb ⇒ + val path = requestHeader.tags(Router.Tags.RoutePattern) + cache.atomicGetOrElseUpdate(s"$verb$path", { + val traceName = { + // Convert paths of form GET /foo/bar/$paramname<regexp>/blah to foo.bar.paramname.blah.get + val p = normalizePattern.replaceAllIn(path, "$1").replace('/', '.').dropWhile(_ == '.') + val normalisedPath = { + if (p.lastOption.exists(_ != '.')) s"$p." + else p + } + s"$normalisedPath${verb.toLowerCase(Locale.ENGLISH)}" + } + traceName + }) + } getOrElse s"${requestHeader.method}: ${requestHeader.uri}" + + def generateHttpClientSegmentName(request: WSRequest): String = request.url }
\ No newline at end of file |