diff options
Diffstat (limited to 'kamon-examples/kamon-play-example/app')
3 files changed, 20 insertions, 13 deletions
diff --git a/kamon-examples/kamon-play-example/app/Global.scala b/kamon-examples/kamon-play-example/app/Global.scala index 5fbb9c7e..535ea308 100644 --- a/kamon-examples/kamon-play-example/app/Global.scala +++ b/kamon-examples/kamon-play-example/app/Global.scala @@ -17,9 +17,4 @@ import filters.TraceLocalFilter import play.api.mvc.WithFilters -object Global extends WithFilters(TraceLocalFilter){ - -} - - - +object Global extends WithFilters(TraceLocalFilter)
\ No newline at end of file diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala index 2b2e9373..7be69f6a 100644 --- a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -15,15 +15,18 @@ * ========================================================== */ package controllers +import kamon.Kamon +import kamon.metric.UserMetrics import kamon.play.action.TraceName import play.api.Logger import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.mvc.{Action, Controller} +import play.libs.Akka import scala.concurrent._ /** - * In order to run the example we need set the -agent parameter to the JVM but Play have some limitations when trying to set an + * In order to run the example we need set the -javaagent option to the JVM, but Play have some limitations when trying to set an * java agent in Play dev mode (ie, play run) -> https://github.com/playframework/playframework/issues/1372, so we have others options: * * The first option is set -javaagent: path-to-aspectj-weaver in your IDE or @@ -51,8 +54,9 @@ import scala.concurrent._ object KamonPlayExample extends Controller { val logger = Logger(this.getClass) + val counter = Kamon(UserMetrics)(Akka.system()).registerCounter("my-counter") - def sayHello() = Action.async { + def sayHello = Action.async { Future { logger.info("Say hello to Kamon") Ok("Say hello to Kamon") @@ -60,12 +64,20 @@ object KamonPlayExample extends Controller { } //using the Kamon TraceName Action to rename the trace name in metrics - def sayHelloWithTraceName() = TraceName("my-trace-name") { + def sayHelloWithTraceName = TraceName("my-trace-name") { Action.async { Future { - logger.info("Say hello to Kamon") - Ok("Say hello to Kamon") + logger.info("Say hello to Kamon with trace name") + Ok("Say hello to Kamon with trace name") } } } + + def incrementCounter = Action.async { + Future { + logger.info("increment") + counter.increment() + Ok("increment") + } + } } diff --git a/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala b/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala index 08ea782c..bf496530 100644 --- a/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala +++ b/kamon-examples/kamon-play-example/app/filters/TraceLocalFilter.scala @@ -27,8 +27,8 @@ object TraceLocalKey extends TraceLocal.TraceLocalKey { } /* - By default Kamon spreads the trace-token-header-name but sometimes is necessary pass through the application requests with some infomation like - extra headers, with kamon it's possible using TraceLocalStorage, in Play applications we can do an Action Filter or using Action Composition, + By default kamon spreads the trace-token-header-name, but sometimes is necessary pass through the application requests with some information like + extra headers, with kamon it's possible using the TraceLocalStorage, in Play applications we can do an Action Filter or using Action Composition, in this example we are using a simple filter where given a Header store the value and then put the value in the result headers.. More detailed usage of TraceLocalStorage: https://github.com/kamon-io/Kamon/blob/b17539d231da923ea854c01d2c69eb02ef1e85b1/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala |