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);
}
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()));
});
}
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()));
});
}
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();
}
Aggregations