Versions Compared

Key

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

...

Distributed Tracing with OpenTracing and JAX-WS support

Distributed tracing in the Apache CXF is build primarily around JAX-RS 2.x implementation. However, JAX-WS is also supported but it requires to write some boiler-plate code and use OpenTracing Java API directly (the JAX-WS integration is going to be enhanced in the future). Essentially, from the server-side prospective the in/out interceptors, OpenTracingStartInterceptor and OpenTracingStopInterceptor respectively, should be configured as part of interceptor chains, either manually or using OpenTracingFeature. For example:

Code Block
java
java
final Tracer tracer = new Configuration("tracer", 
        new Configuration.SamplerConfiguration(ConstSampler.TYPE, 1), /* or any other Sampler */
        new Configuration.ReporterConfiguration(new HttpSender("http://localhost:14268/api/traces")) /* or any other Sender */
    ).getTracer();

final JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
...
sf.getFeatures().add(new OpenTracingFeature(trace));
...
sf.create();

Similarly to the server-side, client-side needs own set of out/in interceptors, OpenTracingClientStartInterceptor and OpenTracingClientStopInterceptor (or OpenTracingClientFeature). Please notice the difference from server-side:  OpenTracingClientStartInterceptor becomes out-interceptor while OpenTracingClientStopInterceptor becomes in-interceptor. For example:

Code Block
java
java
final Tracer tracer = new Configuration("tracer", 
        new Configuration.SamplerConfiguration(ConstSampler.TYPE, 1), /* or any other Sampler */
        new Configuration.ReporterConfiguration(new HttpSender("http://localhost:14268/api/traces")) /* or any other Sender */
    ).getTracer();
              
final JaxWsProxyFactoryBean sf = new JaxWsProxyFactoryBean();
...
sf.getFeatures().add(new OpenTracingClientFeature(tracer));
...
sf.create();

As it was mentioned before, you may use GlobalTracer utility class to pass the tracer around so, for example, any JAX-WS service will be able to retrieve the current tracer by invoking GlobalTracer.get() method.