From 0279260cde60505f311aeed08b4706a4dc6fded0 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 28 Jun 2014 11:37:00 -0300 Subject: + kamon-examples: updated play example to the latest version --- .../app/controllers/KamonPlayExample.scala | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala (limited to 'kamon-examples/kamon-play-example/app/controllers') diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala new file mode 100644 index 00000000..e5fd78b0 --- /dev/null +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -0,0 +1,49 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ +package controllers + +import play.api.Logger +import play.api.libs.concurrent.Execution.Implicits.defaultContext +import play.api.mvc.{Action, Controller} + +import scala.concurrent._ + +/* + +curl -i -H 'X-Trace-Token:kamon-test' -H 'MyTraceLocalStorageKey:extra-header' -X GET "http://localhost:9000/helloKamon" + +we should get: + +HTTP/1.1 200 OK +Content-Type: text/plain; charset=utf-8 +MyTraceLocalStorageKey: extra-header -> Extra Information +X-Trace-Token: kamon-test -> default Trace-Token +Content-Length: 18 + +Say hello to Kamon + + */ +object KamonPlayExample extends Controller { + + val logger = Logger(this.getClass) + + def sayHelloKamon() = Action.async { + Future { + logger.info("Say hello to Kamon") + Ok("Say hello to Kamon") + } + } +} -- cgit v1.2.3 From 345b195782adc825cc4f97eb8d1c87ea22d1d0f9 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 28 Jun 2014 13:05:52 -0300 Subject: = kamon-examples: updated play example with the TraceName Action --- .../app/controllers/KamonPlayExample.scala | 13 ++++++++++++- kamon-examples/kamon-play-example/conf/routes | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'kamon-examples/kamon-play-example/app/controllers') diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala index e5fd78b0..62e36c16 100644 --- a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -15,6 +15,7 @@ * ========================================================== */ package controllers +import kamon.play.action.TraceName import play.api.Logger import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.mvc.{Action, Controller} @@ -40,10 +41,20 @@ object KamonPlayExample extends Controller { val logger = Logger(this.getClass) - def sayHelloKamon() = Action.async { + def sayHello() = Action.async { Future { logger.info("Say hello to Kamon") Ok("Say hello to Kamon") } } + + //using the Kamon TraceName Action to rename the trace name in metrics + def sayHelloWithTraceName() = TraceName("my-trace-name") { + Action.async { + Future { + logger.info("Say hello to Kamon") + Ok("Say hello to Kamon") + } + } + } } diff --git a/kamon-examples/kamon-play-example/conf/routes b/kamon-examples/kamon-play-example/conf/routes index 6c7733cc..122c355a 100644 --- a/kamon-examples/kamon-play-example/conf/routes +++ b/kamon-examples/kamon-play-example/conf/routes @@ -1,2 +1,3 @@ # Routes -GET /helloKamon controllers.KamonPlayExample.sayHelloKamon \ No newline at end of file +GET /helloKamon controllers.KamonPlayExample.sayHello +GET /helloKamonWithTraceName controllers.KamonPlayExample.sayHelloWithTraceName \ No newline at end of file -- cgit v1.2.3 From 42b554f353bf7d94c642d4dd99d1030848f86bc4 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 30 Jun 2014 14:48:02 -0300 Subject: = kamon-play-example: explain how run the example --- .../app/controllers/KamonPlayExample.scala | 19 +++++++++++++++++-- kamon-examples/kamon-play-example/project/Build.scala | 7 ++++--- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'kamon-examples/kamon-play-example/app/controllers') diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala index 62e36c16..26b0af7b 100644 --- a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -22,7 +22,21 @@ import play.api.mvc.{Action, Controller} 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 setear 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 + +Run the following commands from console: + +1- play stage +2- cd target/universal/stage +3- java -cp ".:lib/*" -javaagent:lib/org.aspectj.aspectjweaver-1.8.1.jar play.core.server.NettyServer + +and finally for test: curl -i -H 'X-Trace-Token:kamon-test' -H 'MyTraceLocalStorageKey:extra-header' -X GET "http://localhost:9000/helloKamon" @@ -35,8 +49,9 @@ X-Trace-Token: kamon-test -> default Trace-Token Content-Length: 18 Say hello to Kamon + **/ **/ + - */ object KamonPlayExample extends Controller { val logger = Logger(this.getClass) diff --git a/kamon-examples/kamon-play-example/project/Build.scala b/kamon-examples/kamon-play-example/project/Build.scala index 9e615314..c348862a 100644 --- a/kamon-examples/kamon-play-example/project/Build.scala +++ b/kamon-examples/kamon-play-example/project/Build.scala @@ -36,9 +36,10 @@ object ApplicationBuild extends Build { )) val dependencies = Seq( - "io.kamon" %% "kamon-core" % "0.3.1", - "io.kamon" %% "kamon-play" % "0.3.1", - "io.kamon" %% "kamon-statsd" % "0.3.1" + "io.kamon" %% "kamon-core" % "0.3.1", + "io.kamon" %% "kamon-play" % "0.3.1", + "io.kamon" %% "kamon-statsd" % "0.3.1", + "org.aspectj" % "aspectjweaver" % "1.8.1" ) val main = Project(appName, file(".")).enablePlugins(play.PlayScala, SbtWeb) -- cgit v1.2.3 From 8bf93c1f26453ef298d965aaa8b9cb932f8b2a64 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 1 Jul 2014 17:18:42 -0300 Subject: = kamon-play-example: fixed typo --- .../app/controllers/KamonPlayExample.scala | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'kamon-examples/kamon-play-example/app/controllers') diff --git a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala index 26b0af7b..2b2e9373 100644 --- a/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example/app/controllers/KamonPlayExample.scala @@ -22,34 +22,30 @@ import play.api.mvc.{Action, Controller} 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 setear 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 - -Run the following commands from console: - -1- play stage -2- cd target/universal/stage -3- java -cp ".:lib/*" -javaagent:lib/org.aspectj.aspectjweaver-1.8.1.jar play.core.server.NettyServer - -and finally for test: - -curl -i -H 'X-Trace-Token:kamon-test' -H 'MyTraceLocalStorageKey:extra-header' -X GET "http://localhost:9000/helloKamon" - -we should get: - -HTTP/1.1 200 OK -Content-Type: text/plain; charset=utf-8 -MyTraceLocalStorageKey: extra-header -> Extra Information -X-Trace-Token: kamon-test -> default Trace-Token -Content-Length: 18 - -Say hello to Kamon - **/ **/ + * 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 + * 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 + * + * Run the following commands from console: + * + * 1- play stage + * 2- cd target/universal/stage + * 3- java -cp ".:lib/*" -javaagent:lib/org.aspectj.aspectjweaver-1.8.1.jar play.core.server.NettyServer + * + * and finally for test: + * + * curl -i -H 'X-Trace-Token:kamon-test' -H 'MyTraceLocalStorageKey:extra-header' -X GET "http://localhost:9000/helloKamon" + * + * we should get: + * HTTP/1.1 200 OK + * Content-Type: text/plain; charset=utf-8 + * MyTraceLocalStorageKey: extra-header -> Extra Information + * X-Trace-Token: kamon-test -> default Trace-Token + * + * Say hello to Kamon + */*/ object KamonPlayExample extends Controller { -- cgit v1.2.3