...
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
| Anchor |
|---|
| configuring client |
|---|
| configuring client |
|---|
|
Configuring ClientThere are a couple of ways the JAX-RS client could be configured, depending on the client implementation. Apache CXF provides its own WebClient which could be configured just like that (in future versions, there would be a simpler ways to do that using client specific features):
| Code Block |
|---|
|
// Configure the spans transport sender
final Sender sender = ...;
/**
* For example:
*
* final Sender sender = LibthriftSender.create("localhost");;
*/
final Brave brave = new Brave.Builder("web-client")
.reporter(AsyncReporter.builder(sender).build())
.traceSampler(Sampler.ALWAYS_SAMPLE) /* or any other Sampler */
.build();
Response response = WebClient
.create("http://localhost:9000/catalog", Arrays.asList(new BraveClientProvider(brave)))
.accept(MediaType.APPLICATION_JSON)
.get();
|
...
| Code Block |
|---|
|
// Configure the spans transport sender
final Sender sender = ...;
/**
* For example:
*
* final Sender sender = LibthriftSender.create("localhost");;
*/
final Brave brave = new Brave.Builder("jaxrs-client")
.reporter(AsyncReporter.builder(sender).build())
.traceSampler(Sampler.ALWAYS_SAMPLE) /* or any other Sampler */
.build();
final BraveClientProvider provider = new BraveClientProvider(brave);
final Client client = ClientBuilder.newClient().register(provider);
final Response response = client
.target("http://localhost:9000/catalog")
.request()
.accept(MediaType.APPLICATION_JSON)
.get(); |
...
| Anchor |
|---|
| configuring server |
|---|
| configuring server |
|---|
|
Configuring ServerServer configuration is a bit simpler than the client one thanks to the feature class available, BraveFeature. Depending on the way the Apache CXF is used to configure JAX-RS services, it could be part of JAX-RS application configuration, for example:
| Code Block |
|---|
|
@ApplicationPath("/")
public class CatalogApplication extends Application {
@Override
public Set<Object> getSingletons() {
// Configure the spans transport sender
final Sender sender = ...;
/**
* For example:
*
* final Sender sender = LibthriftSender.create("localhost");;
*/
final Brave brave = new Brave.Builder("tracer")
.reporter(AsyncReporter.builder(sender).build())
.traceSampler(Sampler.ALWAYS_SAMPLE) /* or any other Sampler */
.build();
return new HashSet<>(
Arrays.asList(
new BraveFeature(brave)
)
);
}
} |
Or it could be configured using JAXRSServerFactoryBean as well, for example:
| Code Block |
|---|
|
// Configure the spans transport sender
final Sender sender = ...;
/**
* For example:
*
* final Sender sender = LibthriftSender.create("localhost");;
*/
final Brave brave = new Brave.Builder("tracer")
.reporter(AsyncReporter.builder(sender).build())
.traceSampler(Sampler.ALWAYS_SAMPLE) /* or any other Sampler */
.build();
final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(/* application instance */, JAXRSServerFactoryBean.class);
factory.setProvider(new BraveFeature(brave));
...
return factory.create();
|
Once the span reporter and sampler are properly configured, all generated spans are going to be collected and available for analysis and/or visualization./ TODO
Distributed Tracing In Action: Usage Scenarios
In the following subsections we are going to walk through many different scenarios to illustrate the distributed tracing in action, starting from the simplest ones and finishing with asynchronous JAX-RS services. All examples assume that configuration has been done (see please Configuring Client and Configuring Server sections above).
Example #1: Client and Server with default distributed tracing configured
...