val XKey = Key.broadcastString("x-key")
val context =
Kamon.currentContext().get(XKey) match {
case None =>
Kamon.currentContext().withKey(XKey, Some("XKey Value"))
case _ => Kamon.currentContext()
}
Kamon.withContext(context) {
for {
result <- httpClient(Get(uri))
} yield result
}
Kamon.init()
as the very first operation in your code. I am deploying my service as a war, and I'm getting an java.lang.reflect.InvocationTargetException
when I call it in the Context Listener. Where should I be calling it?Hi! Is there a way to specify custom bucket limits? for example i used seconds Kamon.histogram("tsr-last-trained-point", MeasurementUnit.time.seconds)
and i get buckets like this
tsr_last_trained_point_seconds_bucket{le="0.005",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.01",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.025",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.05",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.075",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.1",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.25",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.5",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="0.75",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="1.0",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="2.5",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="5.0",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="7.5",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="10.0",granularity="HOUR"} 0.0
tsr_last_trained_point_seconds_bucket{le="+Inf",granularity="HOUR"} 50.0
tsr_last_trained_point_seconds_count{granularity="HOUR"} 50.0
tsr_last_trained_point_seconds_sum{granularity="HOUR"} 102740.0
But i want buckets like 3600 (hour), 86100(day), week and etc... How can i define histogram like this?
I already got kamon working using the full ?kamon-bundle
but I can see that it adds a lot of dependencies which I dont need/want.
Whats the best way to pick only the things I need put still get the same auto instrumentation as if I would use the full bundle?
Lets say I only want to use: kamon-executors
, kamon-scala-future
, kamon-cassandra
.
I think I could just exclude all other modules via libraryExclusions
but imo the other way around, including only what I want, would be better.
build.sbt
and saw that the kamon-bundle
dependsOn
a lot of modules and I mistakenly assumed that all those modules would be automatically pulled in if I add kamon-bundle
as a dependency to my project.kamon-bundle
and kamon-core
beeing pulled in if I just specify kamon-bundle
as a dependecy. So it looks fine.Counter
, Gauge
etc more advanced or is it just a matter of additional abstraction over the actual metrics implementation which is beneficial?
using kamon to report metrics from a play application (play 2.6.6)
libraryDependencies += "io.kamon" %% "kamon-bundle" % "2.1.0"
libraryDependencies += "io.kamon" %% "kamon-prometheus" % "2.1.0"
I create a custom metric that captures number of requests per customer account (there are a handful of those). I want to get the method called, and the http response status for each request. I initialize it:code
private val requestsByAccountCounter = Kamon.counter("requests_by_account")
I have an ActionBuilder where I increment the counter
requestsByAccountCounter.withTag("account", accountInHeader(request))
.withTag("method", s"${uriBaseFromPath(request.path)}")
.withTag("http_status", r.header.status).increment()
3 metrics are generated
requests_by_account_total{account="TestAccountId"} 0.0
requests_by_account_total{account="TestAccountId",method="/data/catalog"} 0.0
requests_by_account_total{account="TestAccountId",http_status="200",method="/data/catalog"} 34.0
I know I can increment each tag, but ideally I'd like only the 3rd metric to be generated.
How can I accomplish that?
val tagSet = TagSet.builder().add("account", accountFromHeader(request))
.add("method", s"${contextFromRequestPath(request.path)}")
.add("http_status", r.header.status).build()
requestsByAccountCounter.withTags(tagSet).increment()
Hi, I have a very strange issue with play's WSClient
: when .url
is called with a URL which contains spaces. The Kamon instrumented clients fails with:
java.net.URISyntaxException: Illegal character in path at index 22: http://localhost/some url with spaces
at java.base/java.net.URI$Parser.fail(URI.java:2913)
at java.base/java.net.URI$Parser.checkChars(URI.java:3084)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3166)
at java.base/java.net.URI$Parser.parse(URI.java:3114)
at java.base/java.net.URI.<init>(URI.java:600)
at play.api.libs.ws.ahc.StandaloneAhcWSRequest.uri$lzycompute(StandaloneAhcWSRequest.scala:61)
at play.api.libs.ws.ahc.StandaloneAhcWSRequest.uri(StandaloneAhcWSRequest.scala:54)
at kamon.instrumentation.play.WSClientUrlInterceptor$$anon$2.path(PlayClientInstrumentation.scala:82)
at kamon.instrumentation.http.OperationNameSettings.operationName(OperationNameSettings.scala:9)
at kamon.instrumentation.http.HttpClientInstrumentation$Default.createClientSpan(HttpClientInstrumentation.scala:135)
at kamon.instrumentation.http.HttpClientInstrumentation$Default.createHandler(HttpClientInstrumentation.scala:105)
at kamon.instrumentation.play.WSClientUrlInterceptor$$anon$1.apply(PlayClientInstrumentation.scala:43)
at kamon.instrumentation.play.WSClientUrlInterceptor$$anon$1.apply(PlayClientInstrumentation.scala:40)
at play.api.libs.ws.ahc.StandaloneAhcWSRequest.execute(StandaloneAhcWSRequest.scala:219)
at play.api.libs.ws.ahc.AhcWSRequest.execute(AhcWSRequest.scala:264)
at play.api.libs.ws.ahc.AhcWSRequest.execute(AhcWSRequest.scala:260)
at play.api.libs.ws.ahc.AhcWSRequest.get(AhcWSRequest.scala:246)
... own code
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:430)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:92)
but if Kamon is not running, it's working fine. Seems to be a bug in PlayClientInstrumentation
to me. Does Kamon expect the url
to be already encoded? WSClient
seems to work fine with non encoded urls.