Package brave.http
Class HttpRuleSampler
- java.lang.Object
-
- brave.http.HttpSampler
-
- brave.http.HttpRuleSampler
-
- All Implemented Interfaces:
brave.sampler.SamplerFunction<HttpRequest>
public final class HttpRuleSampler extends HttpSampler 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 asHttpRequest
methods can return null.- Since:
- 4.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpRuleSampler.Builder
-
Field Summary
-
Fields inherited from class brave.http.HttpSampler
NEVER_SAMPLE, TRACE_ID
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static HttpRuleSampler.Builder
newBuilder()
<Req> Boolean
trySample(HttpAdapter<Req,?> adapter, Req request)
Deprecated.Boolean
trySample(HttpRequest request)
-
-
-
Method Detail
-
newBuilder
public static HttpRuleSampler.Builder newBuilder()
- Since:
- 4.4
-
trySample
public Boolean trySample(HttpRequest request)
- Specified by:
trySample
in interfacebrave.sampler.SamplerFunction<HttpRequest>
- Overrides:
trySample
in classHttpSampler
-
trySample
@Deprecated public <Req> Boolean trySample(HttpAdapter<Req,?> adapter, Req request)
Deprecated.Description copied from class:HttpSampler
Returns an overriding sampling decision for a new trace. Return null ignore the request and use thetrace ID sampler
.- Specified by:
trySample
in classHttpSampler
-
-