diff options
author | Diego <diegolparra@gmail.com> | 2015-07-19 23:54:40 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2015-07-19 23:54:40 -0300 |
commit | c0a0428f0f32c77e904e4bb1be9e9d1dd801fdb1 (patch) | |
tree | 5e7414ad6198827806f14f21a21060a8ecd915c0 | |
parent | 46e96892bab4f4fd0e941ccd53a3d672db90f5a2 (diff) | |
download | Kamon-c0a0428f0f32c77e904e4bb1be9e9d1dd801fdb1.tar.gz Kamon-c0a0428f0f32c77e904e4bb1be9e9d1dd801fdb1.tar.bz2 Kamon-c0a0428f0f32c77e904e4bb1be9e9d1dd801fdb1.zip |
+ play-examples: new play 2.4.x example
-rw-r--r-- | kamon-examples/kamon-play-2.4.x-example/app/Global.scala | 26 | ||||
-rw-r--r-- | kamon-examples/kamon-play-2.4.x-example/conf/logger.xml | 19 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/app/Filters.scala (renamed from kamon-examples/kamon-play-2.4.x-example/app/Filters.scala) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/app/controllers/KamonPlayExample.scala (renamed from kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala) | 15 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/app/filters/TraceLocalFilter.scala (renamed from kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala) | 14 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/conf/application.conf (renamed from kamon-examples/kamon-play-2.4.x-example/conf/application.conf) | 11 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/conf/logger.xml | 27 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/conf/routes (renamed from kamon-examples/kamon-play-2.4.x-example/conf/routes) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/project/Build.scala (renamed from kamon-examples/kamon-play-2.4.x-example/project/Build.scala) | 6 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/project/build.properties (renamed from kamon-examples/kamon-play-2.4.x-example/project/build.properties) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/project/plugins.sbt (renamed from kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/images/favicon.png (renamed from kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png) | bin | 687 -> 687 bytes | |||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings-white.png (renamed from kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png) | bin | 8777 -> 8777 bytes | |||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings.png (renamed from kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png) | bin | 12799 -> 12799 bytes | |||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/javascripts/jquery-1.9.0.min.js (renamed from kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/stylesheets/bootstrap.css (renamed from kamon-examples/kamon-play-2.4.x-example/public/stylesheets/bootstrap.css) | 0 | ||||
-rw-r--r-- | kamon-examples/kamon-play-example-2.4.x/public/stylesheets/main.css (renamed from kamon-examples/kamon-play-2.4.x-example/public/stylesheets/main.css) | 0 |
17 files changed, 53 insertions, 65 deletions
diff --git a/kamon-examples/kamon-play-2.4.x-example/app/Global.scala b/kamon-examples/kamon-play-2.4.x-example/app/Global.scala deleted file mode 100644 index 8d43fbdc..00000000 --- a/kamon-examples/kamon-play-2.4.x-example/app/Global.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* =================================================== - * Copyright © 2013-2014 the kamon project <http://kamon.io/> - * - * 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. - * ========================================================== */ - -import filters.TraceLocalFilter -import play.api.mvc.WithFilters -import play.api.Application -import kamon.Kamon - -object Global extends WithFilters(TraceLocalFilter) { - override def onStart(app: Application) { - Kamon.start() - } -} diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml b/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml deleted file mode 100644 index 56b3c33e..00000000 --- a/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml +++ /dev/null @@ -1,19 +0,0 @@ -<configuration scan="true"> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <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="ASYNC" /> - </root> - -</configuration> diff --git a/kamon-examples/kamon-play-2.4.x-example/app/Filters.scala b/kamon-examples/kamon-play-example-2.4.x/app/Filters.scala index 0ae2747a..0ae2747a 100644 --- a/kamon-examples/kamon-play-2.4.x-example/app/Filters.scala +++ b/kamon-examples/kamon-play-example-2.4.x/app/Filters.scala diff --git a/kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-example-2.4.x/app/controllers/KamonPlayExample.scala index d6b0f771..bb886dfe 100644 --- a/kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala +++ b/kamon-examples/kamon-play-example-2.4.x/app/controllers/KamonPlayExample.scala @@ -16,13 +16,12 @@ package controllers import filters.{TraceLocalContainer, TraceLocalKey} -import kamon.Kamon import kamon.play.action.TraceName +import kamon.play.di.Kamon import kamon.trace.TraceLocal import play.api.Logger import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.mvc.{Action, Controller} -import play.libs.Akka import javax.inject._ import scala.concurrent._ @@ -36,8 +35,8 @@ import scala.concurrent._ * 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 + * 2- cd target/universal/stage/bin + * 3- ./kamon-play-example -J-javaagent:../lib/org.aspectj.aspectjweaver-1.8.6.jar * * and finally for test: * @@ -50,13 +49,13 @@ import scala.concurrent._ * X-Trace-Token: kamon-test -> default Trace-Token * * Say hello to Kamon - */*/ + **/ -class KamonPlayExample extends Controller { +class KamonPlayExample @Inject() (kamon: Kamon) extends Controller { val logger = Logger(this.getClass) - val counter = Kamon.metrics.counter("my-counter") + val counter = kamon.metrics.counter("my-counter") def sayHello = Action.async { Future { @@ -83,7 +82,7 @@ class KamonPlayExample extends Controller { } } - def updateTraceLocal = Action.async { + def updateTraceLocal() = Action.async { Future { TraceLocal.store(TraceLocalKey)(TraceLocalContainer("MyTraceToken","MyImportantHeader")) logger.info("storeInTraceLocal") diff --git a/kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala b/kamon-examples/kamon-play-example-2.4.x/app/filters/TraceLocalFilter.scala index 8a92aa66..523e2048 100644 --- a/kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala +++ b/kamon-examples/kamon-play-example-2.4.x/app/filters/TraceLocalFilter.scala @@ -17,6 +17,7 @@ package filters import kamon.trace.TraceLocal +import kamon.trace.TraceLocal.{AvailableToMdc, TraceLocalKey} import play.api.Logger import play.api.mvc.{Result, RequestHeader, Filter} import play.api.libs.concurrent.Execution.Implicits.defaultContext @@ -24,9 +25,7 @@ import scala.concurrent.Future case class TraceLocalContainer(traceToken:String, importantHeader:String) -object TraceLocalKey extends TraceLocal.TraceLocalKey { - type ValueType = TraceLocalContainer -} +object TraceLocalKey extends TraceLocalKey[TraceLocalContainer] /* By default kamon spreads the trace-token-header-name, but sometimes is necessary pass through the application requests with some information like @@ -39,16 +38,21 @@ object TraceLocalFilter extends Filter { val logger = Logger(this.getClass) val TraceLocalStorageKey = "MyTraceLocalStorageKey" + val userAgentHeader = "User-Agent" + + //this value will be available in the MDC at the moment to call to Logger.*()s + val UserAgentHeaderAvailableToMDC = AvailableToMdc(userAgentHeader) + override def apply(next: (RequestHeader) ⇒ Future[Result])(header: RequestHeader): Future[Result] = { def onResult(result:Result) = { val traceLocalContainer = TraceLocal.retrieve(TraceLocalKey).getOrElse(TraceLocalContainer("unknown","unknown")) - logger.info(s"traceTokenValue: ${traceLocalContainer.traceToken}") - result.withHeaders((TraceLocalStorageKey -> traceLocalContainer.traceToken)) + result.withHeaders(TraceLocalStorageKey -> traceLocalContainer.traceToken) } //update the TraceLocalStorage TraceLocal.store(TraceLocalKey)(TraceLocalContainer(header.headers.get(TraceLocalStorageKey).getOrElse("unknown"), "unknown")) + TraceLocal.store(UserAgentHeaderAvailableToMDC)(header.headers.get(userAgentHeader).getOrElse("unknown")) //call the action next(header).map(onResult) diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/application.conf b/kamon-examples/kamon-play-example-2.4.x/conf/application.conf index 75a80d8c..c42c6459 100644 --- a/kamon-examples/kamon-play-2.4.x-example/conf/application.conf +++ b/kamon-examples/kamon-play-example-2.4.x/conf/application.conf @@ -1,7 +1,4 @@ #kamon related configuration -akka { - extensions = ["kamon.statsd.StatsD", "kamon.system.SystemMetrics", "kamon.logreporter.LogReporter"] -} kamon { @@ -42,6 +39,12 @@ kamon { include-trace-token-header = true trace-token-header-name = "X-Trace-Token" } + + modules { + kamon-statsd.auto-start = no + kamon-log-reporter.auto-start = yes + kamon-system-metrics.auto-start = no + } } # This is the main configuration file for the application. @@ -55,7 +58,7 @@ application.secret = "3BLM`<aD^5r/L[MinNdw8Tp@915n0djY[g66OSOLi@?k`>AZE9EOphrmf; # The application languages # ~~~~~ -play.i18n.langs = [ "en"] +play.i18n.langs = ["en"] # HttpRequestHandler play.http.requestHandler = "play.http.DefaultHttpRequestHandler" diff --git a/kamon-examples/kamon-play-example-2.4.x/conf/logger.xml b/kamon-examples/kamon-play-example-2.4.x/conf/logger.xml new file mode 100644 index 00000000..416687bd --- /dev/null +++ b/kamon-examples/kamon-play-example-2.4.x/conf/logger.xml @@ -0,0 +1,27 @@ +<configuration scan="true"> + + <!-- + if we use the AsyncAppender this value will not be available at the moment of log, + because the operation is executed in another ThreadPool, + in that case we need put the value the MDC like the [%X{User-Agent}] + --> + <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{User-Agent}] [%thread] %logger{55} - %msg%n</pattern> + </encoder>%traceToken + </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" /> + </root> + +</configuration> diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/routes b/kamon-examples/kamon-play-example-2.4.x/conf/routes index 6aae1d8e..6aae1d8e 100644 --- a/kamon-examples/kamon-play-2.4.x-example/conf/routes +++ b/kamon-examples/kamon-play-example-2.4.x/conf/routes diff --git a/kamon-examples/kamon-play-2.4.x-example/project/Build.scala b/kamon-examples/kamon-play-example-2.4.x/project/Build.scala index a2d65d64..b96b2436 100644 --- a/kamon-examples/kamon-play-2.4.x-example/project/Build.scala +++ b/kamon-examples/kamon-play-example-2.4.x/project/Build.scala @@ -20,7 +20,7 @@ object ApplicationBuild extends Build { ) val defaultSettings = Seq( - scalaVersion := "2.11.7", + scalaVersion := "2.10.5", resolvers ++= resolutionRepos, scalacOptions := Seq( "-encoding", @@ -35,11 +35,11 @@ object ApplicationBuild extends Build { "-Xlog-reflective-calls" )) - val kamonVersion = "0.4.0" + val kamonVersion = "0.4.1-SNAPSHOT" val dependencies = Seq( "io.kamon" %% "kamon-core" % kamonVersion, - "io.kamon" %% "kamon-play" % kamonVersion, + "io.kamon" %% "kamon-play-24" % kamonVersion, "io.kamon" %% "kamon-statsd" % kamonVersion, "io.kamon" %% "kamon-log-reporter" % kamonVersion, "io.kamon" %% "kamon-system-metrics" % kamonVersion, diff --git a/kamon-examples/kamon-play-2.4.x-example/project/build.properties b/kamon-examples/kamon-play-example-2.4.x/project/build.properties index a6e117b6..a6e117b6 100644 --- a/kamon-examples/kamon-play-2.4.x-example/project/build.properties +++ b/kamon-examples/kamon-play-example-2.4.x/project/build.properties diff --git a/kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt b/kamon-examples/kamon-play-example-2.4.x/project/plugins.sbt index f0037325..f0037325 100644 --- a/kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt +++ b/kamon-examples/kamon-play-example-2.4.x/project/plugins.sbt diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png b/kamon-examples/kamon-play-example-2.4.x/public/images/favicon.png Binary files differindex c7d92d2a..c7d92d2a 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png +++ b/kamon-examples/kamon-play-example-2.4.x/public/images/favicon.png diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png b/kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings-white.png Binary files differindex 3bf6484a..3bf6484a 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png +++ b/kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings-white.png diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png b/kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings.png Binary files differindex a9969993..a9969993 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png +++ b/kamon-examples/kamon-play-example-2.4.x/public/images/glyphicons-halflings.png diff --git a/kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js b/kamon-examples/kamon-play-example-2.4.x/public/javascripts/jquery-1.9.0.min.js index 50d1b22f..50d1b22f 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js +++ b/kamon-examples/kamon-play-example-2.4.x/public/javascripts/jquery-1.9.0.min.js diff --git a/kamon-examples/kamon-play-2.4.x-example/public/stylesheets/bootstrap.css b/kamon-examples/kamon-play-example-2.4.x/public/stylesheets/bootstrap.css index 2f56af33..2f56af33 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/stylesheets/bootstrap.css +++ b/kamon-examples/kamon-play-example-2.4.x/public/stylesheets/bootstrap.css diff --git a/kamon-examples/kamon-play-2.4.x-example/public/stylesheets/main.css b/kamon-examples/kamon-play-example-2.4.x/public/stylesheets/main.css index e69de29b..e69de29b 100644 --- a/kamon-examples/kamon-play-2.4.x-example/public/stylesheets/main.css +++ b/kamon-examples/kamon-play-example-2.4.x/public/stylesheets/main.css |