Search in sources :

Example 1 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method setUp.

@Before
public void setUp() {
    TestSpanReporter.clear();
    brave = Tracing.newBuilder().reporter(new TestSpanReporter()).sampler(Sampler.ALWAYS_SAMPLE).build();
    braveClientProvider = new BraveClientProvider(brave);
    random = new Random();
}
Also used : Random(java.util.Random) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) Before(org.junit.Before)

Example 2 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient.

@Test
public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
    final Span span = brave.tracer().nextSpan().name("test span").start();
    try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
        final Future<Response> f = client.async().get();
        final Response r = f.get(1, TimeUnit.SECONDS);
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
        assertThat(brave.tracer().currentSpan().context().spanId(), equalTo(span.context().spanId()));
        assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
        assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
        assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
        assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
    } finally {
        span.finish();
    }
    // Await till flush happens, usually a second is enough
    await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanReporter.getAllSpans().size() == 4);
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
    assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}
Also used : Response(javax.ws.rs.core.Response) SpanInScope(brave.Tracer.SpanInScope) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Span(brave.Span) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan) Test(org.junit.Test)

Example 3 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatProvidedSpanIsNotClosedWhenActive.

@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
    final WebClient client = createWebClient("/bookstore/books", new BraveClientProvider(brave));
    final Span span = brave.tracer().nextSpan().name("test span").start();
    try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
        final Response r = client.get();
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
        assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
        assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
        assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
        assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
        assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
    } finally {
        span.finish();
    }
    // Await till flush happens, usually a second is enough
    await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanReporter.getAllSpans().size() == 4);
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
    assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}
Also used : Response(javax.ws.rs.core.Response) SpanInScope(brave.Tracer.SpanInScope) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Span(brave.Span) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan) Test(org.junit.Test)

Example 4 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method setUp.

@Before
public void setUp() {
    TestSpanHandler.clear();
    brave = Tracing.newBuilder().addSpanHandler(new TestSpanHandler()).sampler(Sampler.ALWAYS_SAMPLE).build();
    braveClientProvider = new BraveClientProvider(brave);
}
Also used : BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) Before(org.junit.Before)

Example 5 with BraveClientProvider

use of org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider in project cxf by apache.

the class BraveTracingTest method testThatNewChildSpanIsCreatedWhenParentIsProvided.

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvided() {
    final Response r = createWebClient("/bookstore/books", new BraveClientProvider(brave)).get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
    assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
    assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
}
Also used : Response(javax.ws.rs.core.Response) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) Test(org.junit.Test)

Aggregations

BraveClientProvider (org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider)9 Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 Span (brave.Span)4 SpanInScope (brave.Tracer.SpanInScope)4 TestSpanReporter (org.apache.cxf.systest.brave.TestSpanReporter)4 HasSpan.hasSpan (org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan)4 Tracing (brave.Tracing)3 Sampler (brave.sampler.Sampler)2 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 MalformedURLException (java.net.MalformedURLException)2 Duration (java.time.Duration)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 TimeUnit (java.util.concurrent.TimeUnit)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2