/** * Scopes this component for a client of the indicated server. * * @see #serverName() */ public HttpTracing clientOf(String serverName) { return toBuilder().serverName(serverName).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 }
/** * 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"); }
/** * 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"); }
/** * 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"); }
@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")); }
httpTracing = httpTracing.toBuilder() .clientParser(new HttpClientParser() { @Override
@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"); }
@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 }
/** * 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"); }
/** * 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"); }
/** * 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"); }
@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")); }
httpTracing = httpTracing.toBuilder() .clientParser(new HttpClientParser() { @Override
@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"); }