diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-12 11:30:06 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-02-13 05:15:30 +0100 |
commit | c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8 (patch) | |
tree | d7dbe6a1007b168998f167ac74a98744542c6fa8 /kamon-play/src/main | |
parent | 6729c9632245328a007332cdcce7d362584d735a (diff) | |
download | Kamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.tar.gz Kamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.tar.bz2 Kamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.zip |
! all: Kamon now works as a single instance in a companion object.
Diffstat (limited to 'kamon-play/src/main')
3 files changed, 13 insertions, 13 deletions
diff --git a/kamon-play/src/main/scala/kamon/play/Play.scala b/kamon-play/src/main/scala/kamon/play/Play.scala index 7ca81028..3c3e4fa7 100644 --- a/kamon-play/src/main/scala/kamon/play/Play.scala +++ b/kamon-play/src/main/scala/kamon/play/Play.scala @@ -20,7 +20,7 @@ import akka.actor.{ ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProv import akka.event.Logging import kamon.Kamon import kamon.http.HttpServerMetrics -import kamon.metric.{ Entity, Metrics } +import kamon.metric.Entity import play.api.libs.ws.WSRequest import play.api.mvc.RequestHeader @@ -37,11 +37,11 @@ class PlayExtension(private val system: ExtendedActorSystem) extends Kamon.Exten private val config = system.settings.config.getConfig("kamon.play") val httpServerMetrics = { - val metricsExtension = Metrics.get(system) + val metricsExtension = Kamon.metrics val factory = metricsExtension.instrumentFactory(HttpServerMetrics.category) val entity = Entity("play-server", HttpServerMetrics.category) - Metrics.get(system).register(entity, new HttpServerMetrics(factory)).recorder + metricsExtension.register(entity, new HttpServerMetrics(factory)).recorder } val defaultDispatcher = system.dispatchers.lookup(config.getString("dispatcher")) 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 38f499b4..e9b2d570 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/RequestInstrumentation.scala @@ -36,14 +36,13 @@ class RequestInstrumentation { @After("call(* play.api.GlobalSettings.onStart(*)) && args(application)") def afterApplicationStart(application: play.api.Application): Unit = { - Kamon(Play)(Akka.system()) + Kamon(Play) } @Before("call(* play.api.GlobalSettings.onRouteRequest(..)) && args(requestHeader)") def beforeRouteRequest(requestHeader: RequestHeader): Unit = { - implicit val system = Akka.system() + import Kamon.tracer val playExtension = Kamon(Play) - val tracer = Kamon(Tracer) val defaultTraceName = playExtension.generateTraceName(requestHeader) val token = if (playExtension.includeTraceToken) { @@ -58,14 +57,14 @@ class RequestInstrumentation { def aroundDoFilter(pjp: ProceedingJoinPoint, next: EssentialAction): Any = { val essentialAction = (requestHeader: RequestHeader) ⇒ { - val executor = Kamon(Play)(Akka.system()).defaultDispatcher + val playExtension = Kamon(Play) + val executor = playExtension.defaultDispatcher def onResult(result: Result): Result = { TraceContext.map { ctx ⇒ ctx.finish() - val playExtension = ctx.lookupExtension(Play) - recordHttpServerMetrics(result.header, ctx.name, playExtension) + recordHttpServerMetrics(result.header, ctx.name) if (playExtension.includeTraceToken) result.withHeaders(playExtension.traceTokenHeaderName -> ctx.token) else result @@ -87,12 +86,12 @@ class RequestInstrumentation { @Before("call(* play.api.GlobalSettings.onError(..)) && args(request, ex)") def beforeOnError(request: TraceContextAware, ex: Throwable): Unit = { TraceContext.map { ctx ⇒ - recordHttpServerMetrics(InternalServerError.header, ctx.name, ctx.lookupExtension(Play)) + recordHttpServerMetrics(InternalServerError.header, ctx.name) } } - def recordHttpServerMetrics(header: ResponseHeader, traceName: String, playExtension: PlayExtension): Unit = - playExtension.httpServerMetrics.recordResponse(traceName, header.status.toString) + def recordHttpServerMetrics(header: ResponseHeader, traceName: String): Unit = + Kamon(Play).httpServerMetrics.recordResponse(traceName, header.status.toString) def storeDiagnosticData(request: RequestHeader): Unit = { val agent = request.headers.get(UserAgent).getOrElse(Unknown) 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 fc58f9da..8b76ab8b 100644 --- a/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala +++ b/kamon-play/src/main/scala/kamon/play/instrumentation/WSInstrumentation.scala @@ -16,6 +16,7 @@ package kamon.play.instrumentation +import kamon.Kamon import kamon.play.Play import kamon.trace.{ TraceContext, SegmentCategory } import org.aspectj.lang.ProceedingJoinPoint @@ -33,7 +34,7 @@ class WSInstrumentation { @Around("onExecuteRequest(request)") def aroundExecuteRequest(pjp: ProceedingJoinPoint, request: WSRequest): Any = { TraceContext.map { ctx ⇒ - val playExtension = ctx.lookupExtension(Play) + val playExtension = Kamon(Play) val executor = playExtension.defaultDispatcher val segmentName = playExtension.generateHttpClientSegmentName(request) val segment = ctx.startSegment(segmentName, SegmentCategory.HttpClient, Play.SegmentLibraryName) |