Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example server-side implementation of the JAX-RS service is going to offload some work into thread pool and then return the response to the client, simulating parallel execution.For this example to work, the OpenZipkin Brave on server side should be con figured configured a little bit differently (using InheritableServerClientAndLocalSpanState):

Code Block
java
java
final Endpoint endpoint =  Endpoint.create("tracer-server",
    ByteBuffer.wrap(Inet4Address.getLocalHost().getAddress()).getInt());
        
final Brave brave = new Brave.Builder(new InheritableServerClientAndLocalSpanState(endpoint))
    .reporter(AsyncReporter.builder(sender).build())
    .traceSampler(Sampler.ALWAYS_SAMPLE)
    .build();

...

In this example server-side implementation of the JAX-RS service is going to be executed asynchronously. It poses a challenge from the tracing prospective as request and response are processed in different threads (in general). At the moment, Apache CXF does not support the transparent tracing spans management (except for default use case) but provides the simple ways to do that (by letting to transfer spans from thread to thread). The client-side code stays unchanged.As with the previous example, the OpenZipkin Brave on server side should be configured a little bit differently (using InheritableServerClientAndLocalSpanState):

Code Block
java
java
final Endpoint endpoint =  Endpoint.create("tracer-server",
    ByteBuffer.wrap(Inet4Address.getLocalHost().getAddress()).getInt());
        
final Brave brave = new Brave.Builder(new InheritableServerClientAndLocalSpanState(endpoint))
    .reporter(AsyncReporter.builder(sender).build())
    .traceSampler(Sampler.ALWAYS_SAMPLE)
    .build();

The client-side code stays unchanged.

Code Block
java
java
@Produces( { MediaType.APPLICATION_JSON } )
@GET
public void getBooks(@Suspended final AsyncResponse @Produces( { MediaType.APPLICATION_JSON } )
@GET
public void getBooks(@Suspended final AsyncResponse response, @Context final TracerContext tracer) throws Exception {
    tracer.continueSpan(new Traceable<Future<Void>>() {
        public Future<Void> call(final TracerContext context) throws Exception {
            return executor.submit(
                tracer.wrap("Getting Book", new Traceable<Void>() {
                    public Void call(final TracerContext context) throws Exception {
                        // Simulating a processing delay of 50ms
                        Thread.sleep(50);
                            
                        response.resume(
                            Arrays.asList(
                                new Book("Apache CXF Web Service Development", "Naveen Balani, Rajeev Hathi")
                            )
                        );
                            
                        return null;
                    }
                })
            );
        }
    });
}

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:

Image Added

Example #7: Client and Server with asynchronous invocation (client-side)

...