Versions Compared

Key

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

...

Distributed Tracing in Apache CXF using OpenTelemetry

The current integration of the OpenTelemetry's distributed tracing in Apache CXF supports OpenTelemetry Java SDK 1.28.0+ (using semantic conventions) and provides full-fledged support of JAX-RS 2.x / JAX-WS applications. From high-level prospective, the JAX-RS integration consists of three main parts:

  • TracerContext (injectable through @Context annotation)
  • OpenTelemetryProvider (server-side JAX-RS provider) and OpenTelemetryClientProvider (client-side JAX-RS provider)

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

  • OpenTelemetryStartInterceptor / OpenTelemetryStopInterceptor / OpenTelemetryFeature Apache CXF feature (server-side JAX-WS support)
  • OpenTelemetryClientStartInterceptor / OpenTelemetryClientStopInterceptor / OpenTelemetryClientFeature 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 specific to distributing tracing framework you have picked and are not configurable at the moment (unless the framework itself has a way to do that).

By default, OpenTelemetryClientProvider will use configured propagators 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 OpenTelemetryClientProvider on the client and OpenTelemetryProvider on the server is enough to have tracing context to be properly passed everywhere. The only configuration part which is necessary are span exporters(s) and sampler(s) which are, not surprisingly, specific to distributing tracing vendor you have chosen.

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/123TBD