diff options
author | Diego <diegolparra@gmail.com> | 2014-09-18 21:37:08 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-09-18 21:37:08 -0300 |
commit | 3744456c5cce979f57c4eb4d5e78490ef5bc1697 (patch) | |
tree | 1ab8946d6076142046ea0e4c523f400ac358c269 /kamon-examples | |
parent | f3aacf437193715405efbafdd8c12f5dcb1105e0 (diff) | |
download | Kamon-3744456c5cce979f57c4eb4d5e78490ef5bc1697.tar.gz Kamon-3744456c5cce979f57c4eb4d5e78490ef5bc1697.tar.bz2 Kamon-3744456c5cce979f57c4eb4d5e78490ef5bc1697.zip |
+ play-example: * updated play to 2.3.3
* TraceLocal to MDC example
* AsyncAppender
Diffstat (limited to 'kamon-examples')
7 files changed, 38 insertions, 20 deletions
diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala index 7be69f6a..b3a8c11f 100644 --- a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -15,9 +15,11 @@ * ========================================================== */ package controllers +import filters.{TraceLocalContainer, TraceLocalKey} import kamon.Kamon import kamon.metric.UserMetrics import kamon.play.action.TraceName +import kamon.trace.TraceLocal import play.api.Logger import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.mvc.{Action, Controller} @@ -80,4 +82,12 @@ object KamonPlayExample extends Controller { Ok("increment") } } + + def updateTraceLocal = Action.async { + Future { + TraceLocal.store(TraceLocalKey)(TraceLocalContainer("MyTraceToken","MyImportantHeader")) + logger.info("storeInTraceLocal") + Ok("storeInTraceLocal") + } + } } diff --git a/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala b/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala index bf496530..c1d5b92e 100644 --- a/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala +++ b/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala @@ -22,8 +22,10 @@ import play.api.mvc.{Result, RequestHeader, Filter} import play.api.libs.concurrent.Execution.Implicits.defaultContext import scala.concurrent.Future +case class TraceLocalContainer(traceToken:String, importantHeader:String) + object TraceLocalKey extends TraceLocal.TraceLocalKey { - type ValueType = String + type ValueType = TraceLocalContainer } /* @@ -38,15 +40,17 @@ object TraceLocalFilter extends Filter { val TraceLocalStorageKey = "MyTraceLocalStorageKey" override def apply(next: (RequestHeader) ⇒ Future[Result])(header: RequestHeader): Future[Result] = { - TraceRecorder.withTraceContext(TraceRecorder.currentContext) { - - TraceLocal.store(TraceLocalKey)(header.headers.get(TraceLocalStorageKey).getOrElse("unknown")) - next(header).map { - val traceTokenValue = TraceLocal.retrieve(TraceLocalKey).getOrElse("unknown") - logger.info(s"traceTokenValue: $traceTokenValue") - result ⇒ result.withHeaders((TraceLocalStorageKey -> traceTokenValue)) - } + def onResult(result:Result) = { + val traceLocalContainer = TraceLocal.retrieve(TraceLocalKey).getOrElse(TraceLocalContainer("unknown","unknown")) + logger.info(s"traceTokenValue: ${traceLocalContainer.traceToken}") + result.withHeaders((TraceLocalStorageKey -> traceLocalContainer.traceToken)) } + + //update the TraceLocalStorage + TraceLocal.store(TraceLocalKey)(TraceLocalContainer(header.headers.get(TraceLocalStorageKey).getOrElse("unknown"), "unknown")) + + //call the action + next(header).map(onResult) } } diff --git a/kamon-examples/kamon-play-example/conf/application.conf b/kamon-examples/kamon-play-example/conf/application.conf index 65a834c6..099700f9 100644 --- a/kamon-examples/kamon-play-example/conf/application.conf +++ b/kamon-examples/kamon-play-example/conf/application.conf @@ -1,6 +1,6 @@ #kamon related configuration akka { - extensions = ["kamon.statsd.StatsD", "kamon.system.SystemMetrics", "kamon.logreporter.LogReporter"] +// extensions = ["kamon.statsd.StatsD", "kamon.system.SystemMetrics", "kamon.logreporter.LogReporter"] } kamon { diff --git a/kamon-examples/kamon-play-example/conf/logger.xml b/kamon-examples/kamon-play-example/conf/logger.xml index 84126e9d..56b3c33e 100644 --- a/kamon-examples/kamon-play-example/conf/logger.xml +++ b/kamon-examples/kamon-play-example/conf/logger.xml @@ -1,16 +1,19 @@ <configuration scan="true"> - <conversionRule conversionWord="traceToken" converterClass="kamon.trace.logging.LogbackTraceTokenConverter" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> - <pattern>%date{HH:mm:ss.SSS} %-5level [%traceToken][%X{akkaSource}] [%thread] %logger{55} - %msg%n</pattern> + <pattern>%date{HH:mm:ss.SSS} %-5level [%X{traceToken}][%X{importantHeader}] [%thread] %logger{55} - %msg%n</pattern> </encoder> </appender> + <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> + <appender-ref ref="STDOUT" /> + </appender> + <logger name="play" level="INFO" /> <logger name="application" level="INFO" /> <root level="INFO"> - <appender-ref ref="STDOUT" /> + <appender-ref ref="ASYNC" /> </root> </configuration> diff --git a/kamon-examples/kamon-play-example/conf/routes b/kamon-examples/kamon-play-example/conf/routes index 2178c946..ecc6cd91 100644 --- a/kamon-examples/kamon-play-example/conf/routes +++ b/kamon-examples/kamon-play-example/conf/routes @@ -1,4 +1,5 @@ # Routes GET /helloKamon controllers.KamonPlayExample.sayHello GET /helloKamonWithTraceName controllers.KamonPlayExample.sayHelloWithTraceName -GET /incrementCounter controllers.KamonPlayExample.incrementCounter
\ No newline at end of file +GET /incrementCounter controllers.KamonPlayExample.incrementCounter +GET /updateTraceLocal controllers.KamonPlayExample.updateTraceLocal
\ No newline at end of file diff --git a/kamon-examples/kamon-play-example/project/Build.scala b/kamon-examples/kamon-play-example/project/Build.scala index c9693c24..e0c048f7 100644 --- a/kamon-examples/kamon-play-example/project/Build.scala +++ b/kamon-examples/kamon-play-example/project/Build.scala @@ -36,11 +36,11 @@ object ApplicationBuild extends Build { )) val dependencies = Seq( - "io.kamon" %% "kamon-core" % "0.3.3", - "io.kamon" %% "kamon-play" % "0.3.3", - "io.kamon" %% "kamon-statsd" % "0.3.3", - "io.kamon" %% "kamon-log-reporter" % "0.3.3", - "io.kamon" %% "kamon-system-metrics" % "0.3.3", + "io.kamon" %% "kamon-core" % "0.3.4-05453bdeb54f4db8f643185c28fec34a77ef5ca9", + "io.kamon" %% "kamon-play" % "0.3.4-05453bdeb54f4db8f643185c28fec34a77ef5ca9", + "io.kamon" %% "kamon-statsd" % "0.3.4-05453bdeb54f4db8f643185c28fec34a77ef5ca9", + "io.kamon" %% "kamon-log-reporter" % "0.3.4-05453bdeb54f4db8f643185c28fec34a77ef5ca9", + "io.kamon" %% "kamon-system-metrics" % "0.3.4-05453bdeb54f4db8f643185c28fec34a77ef5ca9", "org.aspectj" % "aspectjweaver" % "1.8.1" ) diff --git a/kamon-examples/kamon-play-example/project/plugins.sbt b/kamon-examples/kamon-play-example/project/plugins.sbt index adc5b325..bd7707a4 100644 --- a/kamon-examples/kamon-play-example/project/plugins.sbt +++ b/kamon-examples/kamon-play-example/project/plugins.sbt @@ -5,5 +5,5 @@ logLevel := Level.Warn resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" // Use the Play sbt plugin for Play projects -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.1") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.3") |