...
Once the span reporter and sampler are properly configured, all generated spans are going to be collected and available for analysis and/or visualization.
Distributed Tracing In Action: Usage Scenarios
In the following subsections we are going to walk through many different scenarios to illustrate the distributed tracing in action, starting from the simplest ones and finishing with asynchronous JAX-RS services. All examples assume that configuration has been done (see please Configuring Client and Configuring Server sections above).
Example #1: Client and Server with default distributed tracing configured
In the first example we are going to see the effect of using default configuration on the client and on the server, with only OpenTracingClientProvider and OpenTracingProvider registered. The JAX-RS resource endpoint is pretty basic stubbed method:
Code Block | ||||
---|---|---|---|---|
| ||||
@Produces( { MediaType.APPLICATION_JSON } )
@GET
public Collection<Book> getBooks() {
return Arrays.asList(
new Book("Apache CXF Web Service Development", "Naveen Balani, Rajeev Hathi")
);
} |
The client is as simple as that:
Code Block | ||||
---|---|---|---|---|
| ||||
final Response response = client
.target("http://localhost:8282/books")
.request()
.accept(MediaType.APPLICATION_JSON)
.get(); |
The actual invocation of the request by the client (with service name tracer-client) and consequent invocation of the service on the server side (service name tracer-server) is going to generate the following sample traces (taken from Jaeger UI):
Example #2: Client and Server with nested trace
In this example server-side implementation of the JAX-RS service is going to call an external system (simulated as a simple delay of 500ms) within its own span. The client-side code stays unchanged.
Code Block | ||||
---|---|---|---|---|
| ||||
@Produces( { MediaType.APPLICATION_JSON } )
@GET
public Collection<Book> getBooks(@Context final TracerContext tracer) throws Exception {
try(final Scope scope = tracer.startSpan("Calling External System")) {
// Simulating a delay of 500ms required to call external system
Thread.sleep(500);
return Arrays.asList(
new Book("Apache CXF Web Service Development", "Naveen Balani, Rajeev Hathi")
);
}
} |
The actual invocation of the request by the client (with service name tracer-client) and consequent invocation of the service on the server side (service name tracer-server) is going to generate the following sample traces (taken from Jaeger UI):