Package brave.http
Class HttpRuleSampler
java.lang.Object
brave.http.HttpSampler
brave.http.HttpRuleSampler
- All Implemented Interfaces:
SamplerFunction<HttpRequest>
public final class HttpRuleSampler extends HttpSampler implements 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 classHttpRuleSampler.Builder -
Field Summary
-
Method Summary
Modifier and Type Method Description static HttpRuleSampler.BuildernewBuilder()<Req> BooleantrySample(HttpAdapter<Req,?> adapter, Req request)Deprecated.BooleantrySample(HttpRequest request)
-
Method Details
-
newBuilder
- Since:
- 4.4
-
trySample
- Specified by:
trySamplein interfaceSamplerFunction<HttpRequest>- Overrides:
trySamplein classHttpSampler
-
trySample
Deprecated.Description copied from class:HttpSamplerReturns an overriding sampling decision for a new trace. Return null ignore the request and use thetrace ID sampler.- Specified by:
trySamplein classHttpSampler
-