diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-15 11:16:21 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-15 11:16:21 +0100 |
commit | cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb (patch) | |
tree | 0f07e794e6fb88e180913a10f57ffaa4e2fa03cc /kamon-play/src | |
parent | 8a532fc8c95a5700721248b6b4f558d9a1dcebcb (diff) | |
download | Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.tar.gz Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.tar.bz2 Kamon-cd300053cfec39dc75c1ea47b08ab5c78fe3f4bb.zip |
! core: move the TraceContext manipulation API to the Tracer companion object.
Diffstat (limited to 'kamon-play/src')
5 files changed, 15 insertions, 16 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/action/KamonTraceActions.scala b/kamon-play/src/main/scala/kamon/play/action/KamonTraceActions.scala index 715cac5e..854989a4 100644 --- a/kamon-play/src/main/scala/kamon/play/action/KamonTraceActions.scala +++ b/kamon-play/src/main/scala/kamon/play/action/KamonTraceActions.scala @@ -16,13 +16,13 @@ package kamon.play.action -import kamon.trace.TraceContext +import kamon.trace.Tracer import play.api.mvc._ import scala.concurrent.Future case class TraceName[A](name: String)(action: Action[A]) extends Action[A] { def apply(request: Request[A]): Future[Result] = { - TraceContext.currentContext.rename(name) + Tracer.currentContext.rename(name) action(request) } lazy val parser = action.parser 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 0ec49493..9079b391 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -16,7 +16,7 @@ package kamon.play.instrumentation import kamon.Kamon -import kamon.play.{ Play, PlayExtension } +import kamon.play.Play import kamon.trace.TraceLocal.{ HttpContextKey, HttpContext } import kamon.trace._ import org.aspectj.lang.ProceedingJoinPoint @@ -24,7 +24,6 @@ import org.aspectj.lang.annotation._ import play.api.Routes import play.api.mvc.Results._ import play.api.mvc._ -import play.libs.Akka @Aspect class RequestInstrumentation { @@ -45,7 +44,7 @@ class RequestInstrumentation { } else None val newContext = token.map(t ⇒ tracer.newContext(defaultTraceName, t)).getOrElse(tracer.newContext(defaultTraceName)) - TraceContext.setCurrentContext(newContext) + Tracer.setCurrentContext(newContext) } @Around("call(* play.api.GlobalSettings.doFilter(*)) && args(next)") @@ -56,7 +55,7 @@ class RequestInstrumentation { val executor = playExtension.defaultDispatcher def onResult(result: Result): Result = { - TraceContext.map { ctx ⇒ + Tracer.currentContext.collect { ctx ⇒ ctx.finish() recordHttpServerMetrics(result.header, ctx.name) @@ -70,7 +69,7 @@ class RequestInstrumentation { storeDiagnosticData(requestHeader) //override the current trace name - normaliseTraceName(requestHeader).map(TraceContext.currentContext.rename) + normaliseTraceName(requestHeader).map(Tracer.currentContext.rename) // Invoke the action next(requestHeader).map(onResult)(executor) @@ -80,7 +79,7 @@ class RequestInstrumentation { @Before("call(* play.api.GlobalSettings.onError(..)) && args(request, ex)") def beforeOnError(request: TraceContextAware, ex: Throwable): Unit = { - TraceContext.map { ctx ⇒ + Tracer.currentContext.collect { ctx ⇒ recordHttpServerMetrics(InternalServerError.header, ctx.name) } } 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 8b76ab8b..db95047d 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala @@ -18,7 +18,7 @@ package kamon.play.instrumentation import kamon.Kamon import kamon.play.Play -import kamon.trace.{ TraceContext, SegmentCategory } +import kamon.trace.{ Tracer, SegmentCategory } import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation.{ Around, Aspect, Pointcut } import play.api.libs.ws.{ WSRequest, WSResponse } @@ -33,7 +33,7 @@ class WSInstrumentation { @Around("onExecuteRequest(request)") def aroundExecuteRequest(pjp: ProceedingJoinPoint, request: WSRequest): Any = { - TraceContext.map { ctx ⇒ + Tracer.currentContext.collect { ctx ⇒ val playExtension = Kamon(Play) val executor = playExtension.defaultDispatcher val segmentName = playExtension.generateHttpClientSegmentName(request) diff --git a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala index e0bbede7..aebcc4d0 100644 --- a/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/RequestInstrumentationSpec.scala @@ -19,7 +19,7 @@ import kamon.Kamon import kamon.metric.instrument.CollectionContext import kamon.play.action.TraceName import kamon.trace.TraceLocal.HttpContextKey -import kamon.trace.{ TraceLocal, TraceContext } +import kamon.trace.{ Tracer, TraceLocal, TraceContext } import org.scalatestplus.play._ import play.api.DefaultGlobal import play.api.http.Writeable @@ -117,7 +117,7 @@ class RequestInstrumentationSpec extends PlaySpec with OneServerPerSuite { "respond to the Async Action with X-Trace-Token and the renamed trace" in { val result = Await.result(route(FakeRequest(GET, "/async-renamed").withHeaders(traceTokenHeader)).get, 10 seconds) - TraceContext.currentContext.name must be("renamed-trace") + Tracer.currentContext.name must be("renamed-trace") Some(result.header.headers(traceTokenHeaderName)) must be(expectedToken) } @@ -185,7 +185,7 @@ class RequestInstrumentationSpec extends PlaySpec with OneServerPerSuite { object TraceLocalFilter extends Filter { override def apply(next: (RequestHeader) ⇒ Future[Result])(header: RequestHeader): Future[Result] = { - TraceContext.withContext(TraceContext.currentContext) { + Tracer.withContext(Tracer.currentContext) { TraceLocal.store(TraceLocalKey)(header.headers.get(traceLocalStorageKey).getOrElse("unknown")) diff --git a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala index 577d9bed..d639fd9f 100644 --- a/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala +++ b/kamon-play/src/test/scala/kamon/play/WSInstrumentationSpec.scala @@ -18,7 +18,7 @@ package kamon.play import kamon.Kamon import kamon.metric.{ EntitySnapshot, TraceMetrics } -import kamon.trace.{ TraceContext, SegmentCategory } +import kamon.trace.{ Tracer, TraceContext, SegmentCategory } import org.scalatest.{ Matchers, WordSpecLike } import org.scalatestplus.play.OneServerPerSuite import play.api.libs.ws.WS @@ -53,9 +53,9 @@ class WSInstrumentationSpec extends WordSpecLike with Matchers with OneServerPer } "propagate the TraceContext outside an Action and complete the WS request" in { - TraceContext.withContext(newContext("trace-outside-action")) { + Tracer.withContext(newContext("trace-outside-action")) { Await.result(WS.url(s"http://localhost:$port/outside").get(), 10 seconds) - TraceContext.currentContext.finish() + Tracer.currentContext.finish() } val snapshot = takeSnapshotOf("trace-outside-action") |