Search in sources :

Example 1 with Tracing

use of brave.Tracing in project cxf by apache.

the class BraveTracingTest method testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault.

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault() throws MalformedURLException {
    final Tracing brave = Tracing.newBuilder().localServiceName("book-store").reporter(new TestSpanReporter()).build();
    final BookStoreService service = createJaxWsService(new Configurator() {

        @Override
        public void configure(final JaxWsProxyFactoryBean factory) {
            factory.getFeatures().add(new BraveClientFeature(brave));
            factory.getOutInterceptors().add(new LoggingOutInterceptor());
            factory.getInInterceptors().add(new LoggingInInterceptor());
        }
    });
    try {
        service.removeBooks();
        fail("Expected SOAPFaultException to be raised");
    } catch (final SOAPFaultException ex) {
    /* expected exception */
    }
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
    assertThat(TestSpanReporter.getAllSpans().get(0).name, equalTo("post /bookstore"));
    assertThat(TestSpanReporter.getAllSpans().get(1).name, equalTo("post http://localhost:" + PORT + "/bookstore"));
    final Map<String, List<String>> response = getResponseHeaders(service);
    assertThatTraceHeadersArePresent(response, false);
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) BraveClientFeature(org.apache.cxf.tracing.brave.BraveClientFeature) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) List(java.util.List) Tracing(brave.Tracing) Test(org.junit.Test)

Example 2 with Tracing

use of brave.Tracing in project cxf by apache.

the class BraveTracingTest method testThatNewChildSpanIsCreatedWhenParentIsProvided.

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvided() throws MalformedURLException {
    final Tracing brave = Tracing.newBuilder().localServiceName("book-store").reporter(new TestSpanReporter()).build();
    final BookStoreService service = createJaxWsService(new Configurator() {

        @Override
        public void configure(final JaxWsProxyFactoryBean factory) {
            factory.getFeatures().add(new BraveClientFeature(brave));
        }
    });
    assertThat(service.getBooks().size(), equalTo(2));
    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("post /bookstore"));
    assertThat(TestSpanReporter.getAllSpans().get(2).name, equalTo("post http://localhost:" + PORT + "/bookstore"));
    final Map<String, List<String>> response = getResponseHeaders(service);
    assertThatTraceHeadersArePresent(response, false);
}
Also used : BraveClientFeature(org.apache.cxf.tracing.brave.BraveClientFeature) BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) List(java.util.List) Tracing(brave.Tracing) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) Test(org.junit.Test)

Example 3 with Tracing

use of brave.Tracing in project cxf by apache.

the class BraveTracingTest method testThatNoSpansAreRecordedWhenNotSampled.

@Test
public void testThatNoSpansAreRecordedWhenNotSampled() {
    final Tracing never = Tracing.newBuilder().reporter(new TestSpanReporter()).sampler(Sampler.NEVER_SAMPLE).build();
    final Response r = createWebClient("/bookstore/books", new BraveClientProvider(never)).get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(0));
    assertThatTraceHeadersArePresent(r, false);
}
Also used : Response(javax.ws.rs.core.Response) Tracing(brave.Tracing) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) BraveClientProvider(org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider) Test(org.junit.Test)

Example 4 with Tracing

use of brave.Tracing in project cxf by apache.

the class BraveTracingTest method testThatProvidedSpanIsNotClosedWhenActive.

@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
    final Tracing brave = Tracing.newBuilder().localServiceName("book-store").reporter(new TestSpanReporter()).build();
    final BookStoreService service = createJaxWsService(new Configurator() {

        @Override
        public void configure(final JaxWsProxyFactoryBean factory) {
            factory.getFeatures().add(new BraveClientFeature(brave));
        }
    });
    final Span span = brave.tracer().nextSpan().name("test span").start();
    try {
        try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
            assertThat(service.getBooks().size(), equalTo(2));
            assertThat(brave.tracer().currentSpan(), not(nullValue()));
            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("post /bookstore"));
            assertThat(TestSpanReporter.getAllSpans().get(2).name, equalTo("post http://localhost:" + PORT + "/bookstore"));
            final Map<String, List<String>> response = getResponseHeaders(service);
            assertThatTraceHeadersArePresent(response, true);
        }
    } finally {
        if (span != null) {
            span.finish();
        }
    }
    assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
    assertThat(TestSpanReporter.getAllSpans().get(3).name, equalTo("test span"));
}
Also used : BraveClientFeature(org.apache.cxf.tracing.brave.BraveClientFeature) SpanInScope(brave.Tracer.SpanInScope) BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) List(java.util.List) Tracing(brave.Tracing) TestSpanReporter(org.apache.cxf.systest.brave.TestSpanReporter) Span(brave.Span) Test(org.junit.Test)

Aggregations

Tracing (brave.Tracing)4 TestSpanReporter (org.apache.cxf.systest.brave.TestSpanReporter)4 Test (org.junit.Test)4 List (java.util.List)3 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)3 BookStoreService (org.apache.cxf.systest.jaxws.tracing.BookStoreService)3 BraveClientFeature (org.apache.cxf.tracing.brave.BraveClientFeature)3 Span (brave.Span)1 SpanInScope (brave.Tracer.SpanInScope)1 Response (javax.ws.rs.core.Response)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 BraveClientProvider (org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider)1