@Test public void makesChildOfCurrentSpan() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } finally { parent.finish(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString()); assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
@Test public void propagatesExtra_newTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); // we report one in-process and one RPC client span assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
@Test public void propagatesExtra_unsampledTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); }
@Test public void redirect() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse().setResponseCode(302) .addHeader("Location: " + url("/bar"))); server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location! ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } catch (RuntimeException e) { // some think 404 is an exception } finally { parent.finish(); } Span client1 = takeSpan(); Span client2 = takeSpan(); assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path"))) .contains("/foo", "/bar"); assertThat(takeSpan().kind()).isNull(); // local }
server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { getAsync(client, "/items/1"); ScopedSpan otherSpan = tracer.startScopedSpan("test2"); try { for (int i = 0; i < 2; i++) {
@GET @Path("{lang}") @Produces(MediaType.TEXT_PLAIN) public Response translateHello(@PathParam("lang") final String lang) { /* START CUSTOM INSTRUMENTATION */ final ScopedSpan span = tracer.startScopedSpan("query-repository"); span.annotate("started-query"); span.tag("lang", Optional.ofNullable(lang).orElse("")); final String hello = repository.find(lang); span.annotate("finished-query"); span.finish(); /* END CUSTOM INSTRUMENTATION */ return Response.ok(hello).build(); }
@Override public V execute() throws IOException { ScopedSpan span = tracer.startScopedSpan(name); try { return delegate.execute(); } catch (RuntimeException | IOException | Error e) { span.error(e); throw e; } finally { span.finish(); } }
@Test public void makesChildOfCurrentSpan() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } finally { parent.finish(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.context().traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .isEqualTo(parent.context().spanIdString()); assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
@Test public void propagatesExtra_newTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); // we report one in-process and one RPC client span assertThat(Arrays.asList(takeSpan(), takeSpan())) .extracting(Span::kind) .containsOnly(null, Span.Kind.CLIENT); }
@Test public void propagatesExtra_unsampledTrace() throws Exception { Tracer tracer = httpTracing.tracing().tracer().withSampler(Sampler.NEVER_SAMPLE); server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey"); get(client, "/foo"); } finally { parent.finish(); } assertThat(server.takeRequest().getHeader(EXTRA_KEY)) .isEqualTo("joey"); }
@Test public void redirect() throws Exception { Tracer tracer = httpTracing.tracing().tracer(); server.enqueue(new MockResponse().setResponseCode(302) .addHeader("Location: " + url("/bar"))); server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location! ScopedSpan parent = tracer.startScopedSpan("test"); try { get(client, "/foo"); } catch (RuntimeException e) { // some think 404 is an exception } finally { parent.finish(); } Span client1 = takeSpan(); Span client2 = takeSpan(); assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path"))) .contains("/foo", "/bar"); assertThat(takeSpan().kind()).isNull(); // local }
server.enqueue(new MockResponse()); ScopedSpan parent = tracer.startScopedSpan("test"); try { getAsync(client, "/items/1"); ScopedSpan otherSpan = tracer.startScopedSpan("test2"); try { for (int i = 0; i < 2; i++) {