Package brave.http
Class HttpRuleSampler
- java.lang.Object
-
- brave.http.HttpRuleSampler
-
- All Implemented Interfaces:
brave.sampler.SamplerFunction<HttpRequest>
public final class HttpRuleSampler extends Object implements brave.sampler.SamplerFunction<HttpRequest>
Assigns sample rates to http routes.Ex. Here's a sampler that traces 100 requests per second to /foo and 10 POST requests to /bar per second. This doesn't start new traces for requests to favicon (which many browsers automatically fetch). Other requests will use a global rate provided by the
tracing component.import static brave.http.HttpRequestMatchers.methodIsEqualTo; import static brave.http.HttpRequestMatchers.pathStartsWith; import static brave.sampler.Matchers.and; httpTracingBuilder.serverSampler(HttpRuleSampler.newBuilder() .putRule(pathStartsWith("/favicon"), Sampler.NEVER_SAMPLE) .putRule(pathStartsWith("/foo"), RateLimitingSampler.create(100)) .putRule(and(methodIsEqualTo("POST"), pathStartsWith("/bar")), RateLimitingSampler.create(10)) .build());Ex. Here's a custom matcher for the endpoint "/play&country=US"
Matcher<HttpRequest> playInTheUSA = request -> { if (!"/play".equals(request.path())) return false; String url = request.url(); if (url == null) return false; String query = URI.create(url).getQuery(); return query != null && query.contains("country=US"); };Implementation notes
Be careful when implementing matchers asHttpRequestmethods can return null.- Since:
- 4.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpRuleSampler.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpRuleSampler.BuildernewBuilder()BooleantrySample(HttpRequest request)
-
-
-
Method Detail
-
newBuilder
public static HttpRuleSampler.Builder newBuilder()
- Since:
- 4.4
-
trySample
public Boolean trySample(HttpRequest request)
- Specified by:
trySamplein interfacebrave.sampler.SamplerFunction<HttpRequest>
-
-