Versions Compared

Key

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

Table of Contents

Overview

OpenTracing is a vendor-neutral open standard for distributed tracing. Essentially, for Java-based projects the specification exists as a set of Java APIs which any distributed tracing solution is welcome to implement. There are quite a few distributed tracing frameworks available which are compatible with OpenTracing, notably Zipkin (via community contributions like bridge from Brave to OpenTracing ), Lightstep and Jaeger. Starting from 3.2.1 release, Apache CXF fully supports integration (through cxf-integration-tracing-opentracing module) with any distributed tracer that provides OpenTracing Java API implementation.

...

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 traceser-server) is going to generate the following sample traces (taken from Jaeger UI):

 


Info

Please notice that timelines are treated as logs events in Jaeger.

...

Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://cxf.apache.org/blueprint/core"
       xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"

       xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
                           http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
                           http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd">

    <bean id="tracingFeature" class="org.apache.cxf.tracing.opentracing.jaxrs.OpenTracingFeature">
        <argument index="0">
            <bean factory-ref="builder" factory-method="build" />
        </argument>
    </bean>
    
    <bean id="metrics" class="com.uber.jaeger.metrics.Metrics">
        <argument index="0">
            <bean class="com.uber.jaeger.metrics.StatsFactoryImpl">
                <argument index="0">
                    <bean class="com.uber.jaeger.metrics.NullStatsReporter" />
                </argument>
            </bean>
        </argument>
    </bean>
    
    <bean id="builder" class="com.uber.jaeger.Tracer.Builder">
        <argument index="0" value="cxf-server" />
        <argument index="1">
            <bean class="com.uber.jaeger.reporters.RemoteReporter">
                <argument index="0" ref="sender" />
                <argument index="1" value="1000"/>
                <argument index="2" value="100"/>
                <argument index="3" ref="metrics"/>
            </bean>
        </argument>
        <argument index="2">
            <bean class="com.uber.jaeger.samplers.ConstSampler">
                <argument index="0" value="true" />
            </bean>
        </argument>
    </bean>
    
    <bean id="sender" class="com.uber.jaeger.senders.HttpSender">
        <argument index="0" value="http://localhost:14268/api/traces" />
    </bean>
    
    <cxf:bus>
        <cxf:features>
            <cxf:logging />
        </cxf:features>
    </cxf:bus>

    <jaxrs:server id="catalogServer" address="/">
        <jaxrs:serviceBeans>
            ...
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref component-id="tracingFeature" />
        </jaxrs:providers>
    </jaxrs:server>
</blueprint>

...

...

Accessing OpenTracing APIs

...

Code Block
java
java
@GET
@Path("/search")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject search(@QueryParam("q") final String query, @Context final TracerContext tracing) throws Exception {
    final GoogleBooksApi api = Feign.builder()
        .client(new TracingClient(new ApacheHttpClient(), tracing.unwrap(Tracer.class)))
        .target(GoogleBooksApi.class, "https://www.googleapis.com/books/v1/volumes");

    final Response response = api.search(query);
    try (final StringReaderReader reader = response.body().asReader()) {
        return Json.createReader(reader).readObject();
    }
}

...