...
Accessing Micrometer Observation APIs
...
The Apache CXF abstracts as much of the tracer-specific APIs behind TracerContext as possible. However, sometimes there is a need to get access to Micrometer Observation APIs in order to leverages the rich set of available instrumentations. To make it possible, TracerContext has a dedicated unwrap method which returns underlying Tracer instance. The snippet below shows off how to use this API and use Micrometer Observation instrumentation for OpenFeign client through MicrometerObservationCapability.
Code Block | ||||
---|---|---|---|---|
| ||||
@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()
.addCapability(new MicrometerObservationCapability(tracing.unwrap(ObservationRegistry.class)))
.target(GoogleBooksApi.class, "https://www.googleapis.com");
final feign.Response response = api.search(query);
try (final Reader reader = response.body().asReader(StandardCharsets.UTF_8)) {
return Json.createReader(reader).readObject();
}
}
|
Using non-JAX-RS clients
TBDThe Apache CXF uses native Micrometer Observation capabilities so the existing instrumentations for different HTTP clients work as expected. The usage of only JAX-RS client is not required.