Search in sources :

Example 1 with OpenTracingClientProvider

use of org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider in project cxf by apache.

the class Client method main.

public static void main(final String[] args) throws Exception {
    final Metrics metrics = new Metrics(new StatsFactoryImpl(new NullStatsReporter()));
    final Tracer.Builder builder = new Tracer.Builder("cxf-client", new RemoteReporter(new HttpSender("http://localhost:14268/api/traces"), 1000, 100, metrics), new ConstSampler(true));
    final OpenTracingClientProvider provider = new OpenTracingClientProvider(builder.build());
    final javax.ws.rs.client.Client client = ClientBuilder.newClient().register(provider);
    final Response response = client.target("http://localhost:8084/catalog").request().accept(MediaType.APPLICATION_JSON).get();
    LOG.info("Response: {}", response.readEntity(String.class));
    response.close();
    // Allow Tracer to flush
    Thread.sleep(1000);
}
Also used : NullStatsReporter(com.uber.jaeger.metrics.NullStatsReporter) Tracer(com.uber.jaeger.Tracer) ClientBuilder(javax.ws.rs.client.ClientBuilder) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) HttpSender(com.uber.jaeger.senders.HttpSender) Response(javax.ws.rs.core.Response) RemoteReporter(com.uber.jaeger.reporters.RemoteReporter) Metrics(com.uber.jaeger.metrics.Metrics) ConstSampler(com.uber.jaeger.samplers.ConstSampler) StatsFactoryImpl(com.uber.jaeger.metrics.StatsFactoryImpl)

Example 2 with OpenTracingClientProvider

use of org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider in project cxf by apache.

the class OpenTracingTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    final Collection<Response> responses = IntStream.range(0, 4).mapToObj(index -> client.async().get()).map(this::get).collect(Collectors.toList());
    for (final Response r : responses) {
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
    }
    assertThat(TestSender.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSender.getAllSpans().get(index).getOperationName(), equalTo("Get Books"));
        assertThat(TestSender.getAllSpans().get(index + 1).getOperationName(), equalTo("GET /bookstore/books"));
        assertThat(TestSender.getAllSpans().get(index + 2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
    });
}
Also used : Response(javax.ws.rs.core.Response) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Arrays(java.util.Arrays) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) IsLogContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsLogContaining.hasItem) CoreMatchers.not(org.hamcrest.CoreMatchers.not) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) Builtin(io.opentracing.propagation.Format.Builtin) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) SpanContext(com.uber.jaeger.SpanContext) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Status(javax.ws.rs.core.Response.Status) Before(org.junit.Before) IsTagContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsTagContaining.hasItem) OpenTracingFeature(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature) Awaitility.await(org.awaitility.Awaitility.await) Matchers.empty(org.hamcrest.Matchers.empty) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Iterator(java.util.Iterator) Duration(org.awaitility.Duration) Tracer(io.opentracing.Tracer) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) TestSender(org.apache.cxf.systest.jaeger.TestSender) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Configuration(com.uber.jaeger.Configuration) Response(javax.ws.rs.core.Response) TextMap(io.opentracing.propagation.TextMap) Ignore(org.junit.Ignore) AbstractBusTestServerBase(org.apache.cxf.testutil.common.AbstractBusTestServerBase) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.opentracing.HasSpan.hasSpan) Entry(java.util.Map.Entry) ConstSampler(com.uber.jaeger.samplers.ConstSampler) ActiveSpan(io.opentracing.ActiveSpan) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 3 with OpenTracingClientProvider

use of org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider in project cxf by apache.

the class OpenTracingTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients.

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
    final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
    // The intention is to make a calls one after another, not in parallel, to ensure the
    // thread have trace contexts cleared out.
    final Collection<Response> responses = IntStream.range(0, 4).mapToObj(index -> client.get()).collect(Collectors.toList());
    for (final Response r : responses) {
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
    }
    assertThat(TestSender.getAllSpans().size(), equalTo(12));
    IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
        assertThat(TestSender.getAllSpans().get(index).getOperationName(), equalTo("Get Books"));
        assertThat(TestSender.getAllSpans().get(index + 1).getOperationName(), equalTo("GET /bookstore/books"));
        assertThat(TestSender.getAllSpans().get(index + 2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
    });
}
Also used : Response(javax.ws.rs.core.Response) IntStream(java.util.stream.IntStream) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Arrays(java.util.Arrays) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) IsLogContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsLogContaining.hasItem) CoreMatchers.not(org.hamcrest.CoreMatchers.not) TimeoutException(java.util.concurrent.TimeoutException) Random(java.util.Random) Builtin(io.opentracing.propagation.Format.Builtin) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) SpanContext(com.uber.jaeger.SpanContext) BookStore(org.apache.cxf.systest.jaxrs.tracing.BookStore) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Status(javax.ws.rs.core.Response.Status) Before(org.junit.Before) IsTagContaining.hasItem(org.apache.cxf.systest.jaxrs.tracing.opentracing.IsTagContaining.hasItem) OpenTracingFeature(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature) Awaitility.await(org.awaitility.Awaitility.await) Matchers.empty(org.hamcrest.Matchers.empty) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Iterator(java.util.Iterator) Duration(org.awaitility.Duration) Tracer(io.opentracing.Tracer) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) TestSender(org.apache.cxf.systest.jaeger.TestSender) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) Configuration(com.uber.jaeger.Configuration) Response(javax.ws.rs.core.Response) TextMap(io.opentracing.propagation.TextMap) Ignore(org.junit.Ignore) AbstractBusTestServerBase(org.apache.cxf.testutil.common.AbstractBusTestServerBase) HasSpan.hasSpan(org.apache.cxf.systest.jaxrs.tracing.opentracing.HasSpan.hasSpan) Entry(java.util.Map.Entry) ConstSampler(com.uber.jaeger.samplers.ConstSampler) ActiveSpan(io.opentracing.ActiveSpan) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 4 with OpenTracingClientProvider

use of org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider in project cxf by apache.

the class OpenTracingTracingTest method setUp.

@Before
public void setUp() {
    TestSender.clear();
    tracer = new Configuration("tracer-test-client", new Configuration.SamplerConfiguration(ConstSampler.TYPE, 1), new Configuration.ReporterConfiguration(new TestSender())).getTracer();
    openTracingClientProvider = new OpenTracingClientProvider(tracer);
    random = new Random();
}
Also used : TestSender(org.apache.cxf.systest.jaeger.TestSender) Configuration(com.uber.jaeger.Configuration) Random(java.util.Random) OpenTracingClientProvider(org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider) Before(org.junit.Before)

Aggregations

OpenTracingClientProvider (org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingClientProvider)4 Configuration (com.uber.jaeger.Configuration)3 ConstSampler (com.uber.jaeger.samplers.ConstSampler)3 Random (java.util.Random)3 Response (javax.ws.rs.core.Response)3 TestSender (org.apache.cxf.systest.jaeger.TestSender)3 Before (org.junit.Before)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 SpanContext (com.uber.jaeger.SpanContext)2 ActiveSpan (io.opentracing.ActiveSpan)2 Tracer (io.opentracing.Tracer)2 Builtin (io.opentracing.propagation.Format.Builtin)2 TextMap (io.opentracing.propagation.TextMap)2 MalformedURLException (java.net.MalformedURLException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2