Versions Compared

Key

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

...

Distributed Tracing in Apache CXF using OpenZipkin Brave

The current integration of distributed tracing in Apache CXF supports OpenZipkin Brave (3.16+ release branch) in JAX-RS 2.x+ and JAX-WS applications, including the applications deploying in OSGi containers. From high-level perspective, JAX-RS 2.x+ integration consists of three main parts:

  • TracerContext (injectable through @Context annotation)
  • BraveProvider (server-side JAX-RS provider) and BraveClientProvider (client-side JAX-RS provider)
  • BraveFeature (server-side JAX-RS feature to simplify OpenZipkin Brave configuration and integration)

Similarly, from high-level perspective, JAX-WS integration includes:

  • BraveStartInterceptor / BraveStopInterceptor / BraveFeature Apache CXF feature (server-side JAX-WS support)
  • BraveClientStartInterceptor / BraveClientStopInterceptor / BraveClientFeature Apache CXF feature (client-side JAX-WS support)

Apache CXF uses HTTP headers to hand off tracing context from the client to the service and from the service to service. Those headers are used internally by OpenZipkin Brave and are not configurable at the moment. The header names are declared in the BraveHttpHeaders class and at the moment include:

  • X-B3-TraceId: 128 or 64-bit trace ID
  • X-B3-SpanId: 64-bit span ID
  • X-B3-ParentSpanId: 64-bit parent span ID
  • X-B3-Sampled: "1" means report this span to the tracing system, "0" means do not

By default, BraveClientProvider will try to pass the currently active span through HTTP headers on each service invocation. If there is no active spans, the new span will be created and passed through HTTP headers on per-invocation basis. Essentially, for JAX-RS applications just registering BraveClientProvider on the client and BraveProvider on the server is enough to have tracing context to be properly passed everywhere. The only configuration part which is necessary are span reports(s) and sampler(s).

It is also worth to mention the way Apache CXF attaches the description to spans. With regards to the client integration, the description becomes a full URL being invoked prefixed by HTTP method, for example: GET http://localhost:8282/books. On the server side integration, the description becomes a relative JAX-RS resource path prefixed by HTTP method, f.e.: GET books, POST book/123