@Test public void customSampler() throws Exception { String path = "/foo"; httpTracing = httpTracing.toBuilder().serverSampler(HttpRuleSampler.newBuilder() .addRule(null, path, 0.0f) .build()).build(); init(); Request request = new Request.Builder().url(url(path)).build(); try (Response response = client.newCall(request).execute()) { assertThat(response.isSuccessful()).isTrue(); } // @After will check that nothing is reported }
Builder(Tracing tracing) { if (tracing == null) throw new NullPointerException("tracing == null"); final ErrorParser errorParser = tracing.errorParser(); this.tracing = tracing; this.serverName = ""; // override to re-use any custom error parser from the tracing component this.clientParser = new HttpClientParser() { @Override protected ErrorParser errorParser() { return errorParser; } }; this.serverParser = new HttpServerParser() { @Override protected ErrorParser errorParser() { return errorParser; } }; this.clientSampler = HttpSampler.TRACE_ID; this.serverSampler(HttpSampler.TRACE_ID); }
@Bean @ConditionalOnMissingBean // NOTE: stable bean name as might be used outside sleuth HttpTracing httpTracing(Tracing tracing, SkipPatternProvider provider, HttpClientParser clientParser, HttpServerParser serverParser, @ClientSampler HttpSampler clientSampler, @Nullable @ServerSampler HttpSampler serverSampler) { HttpSampler combinedSampler = combineUserProvidedSamplerWithSkipPatternSampler( serverSampler, provider); return HttpTracing.newBuilder(tracing).clientParser(clientParser) .serverParser(serverParser).clientSampler(clientSampler) .serverSampler(combinedSampler).build(); }
.clientSampler(clientSampler) .serverParser(serverParser) .serverSampler(serverSampler) .build();
@Bean HttpTracing httpTracing(Tracing tracing) { return HttpTracing.newBuilder(tracing) // server starts traces for read requests under the path /api .serverSampler( new HttpSampler() { @Override public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req request) { return "GET".equals(adapter.method(request)) && adapter.path(request).startsWith("/api"); } }) // client doesn't start new traces .clientSampler(HttpSampler.NEVER_SAMPLE) .build(); }
@Override public HttpTracing getObject() { HttpTracing.Builder builder = HttpTracing.newBuilder(tracing); if (clientParser != null) builder.clientParser(clientParser); if (serverParser != null) builder.serverParser(serverParser); if (clientSampler != null) builder.clientSampler(clientSampler); if (serverSampler != null) builder.serverSampler(serverSampler); return builder.build(); }
@Bean @ConditionalOnMissingBean // NOTE: stable bean name as might be used outside sleuth HttpTracing httpTracing(Tracing tracing, SkipPatternProvider provider) { HttpSampler serverSampler = combineUserProvidedSamplerWithSkipPatternSampler( provider); return HttpTracing.newBuilder(tracing).clientParser(this.clientParser) .serverParser(this.serverParser).clientSampler(this.clientSampler) .serverSampler(serverSampler).build(); }
@Test public void customSampler() throws Exception { String path = "/foo"; httpTracing = httpTracing.toBuilder().serverSampler(HttpRuleSampler.newBuilder() .addRule(null, path, 0.0f) .build()).build(); init(); Request request = new Request.Builder().url(url(path)).build(); try (Response response = client.newCall(request).execute()) { assertThat(response.isSuccessful()).isTrue(); } // @After will check that nothing is reported }
@Override public HttpTracing getObject() { HttpTracing.Builder builder = HttpTracing.newBuilder(tracing); if (clientParser != null) builder.clientParser(clientParser); if (serverParser != null) builder.serverParser(serverParser); if (clientSampler != null) builder.clientSampler(clientSampler); if (serverSampler != null) builder.serverSampler(serverSampler); return builder.build(); }