Description
I just realised there is support in kamon 2.x for providing a custom Sampler
implementation just by configuring it
sampler = "com.area51.CustomSampler"
A bit of hidden feature as it doesn't seem to be documented anywhere....:)
Anyways my issue is that the sampler trait only provides the operation name to use as decision point which is kind of pointless for akka-http client operations as the name contains the actual HTTP operation e.g. GET, POST,...
A simple way to test this:
First a custom sampler
class CustomSampler extends Sampler {
override def decide(operation: Sampler.Operation): Trace.SamplingDecision = {
println("sample? -> "+operation.operationName())
Trace.SamplingDecision.Sample
}
}
Then a simple akka-http route
private lazy val route: Route =
pathPrefix("health") {
get {
complete(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "OK!"))
}
}
Using the akka-http client like this
Http().singleRequest(HttpRequest(uri = s"http://localhost:$port/health"))
Will render a printout like
sample? -> GET
If I direct a browser towards my local app I instead get a printout like
sample? -> /health
So on the server side of the sampling decision I get the URL which makes it much more usable.
Having the custom sampler on the client side is useless as I can't make any decision based purely on the HTTP operation.
The use cases I'm trying to solve_
- apps periodically poll Consul for config and service updates - These lookups URL's I don't want sampled at all.
- An orchestration system periodically polls a
/health
URL on the apps - These I don't want sampled either
Yes there's the new AdaptiveSampler but I want a random sampler with a filtering capability.
This because I want to be able to control the sampling density in runtime just by tweaking probability setting AND have the filtering capability.
Could have been solved in a custom sampler provided I would get more relevant information to make the decision on.