.clientParser(new HttpClientParser() { @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, .build().clientOf("remote-service");
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(); }
.clientParser(clientParser) .clientSampler(clientSampler) .serverParser(serverParser) .serverSampler(serverSampler) .build();
.clientParser(new HttpClientParser() { @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, .build().clientOf("remote-service");
@Test public void supportsPortableCustomization() throws Exception { httpTracing = httpTracing.toBuilder().serverParser(new HttpServerParser() { @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { customizer.tag("http.url", adapter.url(req)); // just the path is logged by default customizer.tag("context.visible", String.valueOf(currentTraceContext.get() != null)); customizer.tag("request_customizer.is_span", (customizer instanceof brave.Span) + ""); } @Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + ""); } }).build(); init(); String uri = "/foo?z=2&yAA=1"; get(uri); Span span = takeSpan(); assertThat(span.tags()) .containsEntry("http.url", url(uri)) .containsEntry("context.visible", "true") .containsEntry("request_customizer.is_span", "false") .containsEntry("response_customizer.is_span", "false"); }
@Override public void run(TranslationServiceConfiguration configuration, Environment environment) { /* START TRACING INSTRUMENTATION */ final KafkaSender sender = KafkaSender.newBuilder() .bootstrapServers(configuration.getKafkaBootstrapServers()).build(); final AsyncReporter<Span> reporter = AsyncReporter.builder(sender).build(); final Tracing tracing = Tracing.newBuilder() .localServiceName("translation-service").sampler(Sampler.ALWAYS_SAMPLE) .spanReporter(reporter).build(); final HttpTracing httpTracing = HttpTracing.newBuilder(tracing).build(); final ApplicationEventListener jerseyTracingFilter = TracingApplicationEventListener .create(httpTracing); environment.jersey().register(jerseyTracingFilter); /* END TRACING INSTRUMENTATION */ final TranslationRepository repository = new TranslationRepository(); final TranslationResource translationResource = new TranslationResource( repository); environment.jersey().register(translationResource); final TranslationServiceHealthCheck healthCheck = new TranslationServiceHealthCheck(); environment.healthChecks().register("translation-service", healthCheck); }
@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(); }
public BraveClientProvider(final Tracing brave) { this( HttpTracing .newBuilder(brave) .clientParser(new HttpClientSpanParser()) .build() ); }
/** * The "/nested/items/{itemId}" endpoint should be implemented by two route expressions: * A path prefix: "/nested" and then a relative expression "/items/{itemId}" */ @Test public void httpRoute_nested() throws Exception { httpTracing = httpTracing.toBuilder().serverParser(addHttpUrlTag).build(); init(); routeBasedRequestNameIncludesPathPrefix("/nested/items"); }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .build() ); }
public BraveFeature(final Tracing tracing) { this( HttpTracing .newBuilder(tracing) .serverParser(new HttpServerSpanParser()) .build() ); }
/** * The "/items/{itemId}" endpoint should return the itemId in the response body, which proves * templating worked (including that it ignores query parameters). Note the route format is * framework specific, ex "/items/:itemId" in vert.x */ @Test public void httpRoute() throws Exception { httpTracing = httpTracing.toBuilder().serverParser(addHttpUrlTag).build(); init(); routeBasedRequestNameIncludesPathPrefix("/items"); }
public BraveClientFeature(final Tracing tracing) { this( HttpTracing .newBuilder(tracing) .clientParser(new HttpClientSpanParser()) .build() ); }
@Test public void customSampler() throws Exception { close(); httpTracing = httpTracing.toBuilder().clientSampler(HttpRuleSampler.newBuilder() .addRule(null, "/foo", 0.0f) .build()).build(); client = newClient(server.getPort()); server.enqueue(new MockResponse()); get(client, "/foo"); RecordedRequest request = server.takeRequest(); assertThat(request.getHeaders().toMultimap()) .containsEntry("x-b3-sampled", asList("0")); }
/** * Sometimes state used to carry http route data is different for async requests. This helps * ensure we don't miss issues like this. */ @Test public void httpRoute_async() throws Exception { httpTracing = httpTracing.toBuilder().serverParser(addHttpUrlTag).build(); init(); routeBasedRequestNameIncludesPathPrefix("/async_items"); }
@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(); }
@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 }
public BraveFeature(final Tracing tracing) { this( HttpTracing .newBuilder(tracing) .serverParser(new HttpServerSpanParser()) .build() ); }
public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) .serverParser(new HttpServerSpanParser()) .build() ); }