...
Code Block |
---|
|
final Tracer tracer = new Configuration("jaxrs-client")
.withSampler(
new SamplerConfiguration()
.withType(ConstSampler.TYPE)
.withParam(1)
)
.withReporter(
new ReporterConfiguration()
.withSender(
new SenderConfiguration()
.withEndpoint("http://localhost:14268/api/traces")
)
)
.getTracer();
// This method should only be called once during the application initialization phase.
GlobalTracer.register(tracer);
// No explicit Tracer instance is required, it will be picked off the GlobalTracer using get() method
final OpenTracingClientProvider provider = new OpenTracingClientProvider(); |
Configuring Server
Server configuration is a bit simpler than the client one thanks to the feature class available, OpenTracingFeature. 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() {
final Tracer tracer = new Configuration("tracer-server")
.withSampler(
new SamplerConfiguration()
.withType(ConstSampler.TYPE)
.withParam(1)
)
.withReporter(
new ReporterConfiguration()
.withSender(
new SenderConfiguration()
.withEndpoint("http://localhost:14268/api/traces")
)
)
.getTracer();
return new HashSet<>(
Arrays.asList(
new OpenTracingFeature(tracer)
)
);
}
} |
Or it could be configured using JAXRSServerFactoryBean as well, for example:
Code Block |
---|
|
final Tracer tracer = new Configuration("tracer-server")
.withSampler(
new SamplerConfiguration()
.withType(ConstSampler.TYPE)
.withParam(1)
)
.withReporter(
new ReporterConfiguration()
.withSender(
new SenderConfiguration()
.withEndpoint("http://localhost:14268/api/traces")
)
)
.getTracer();
final JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint(/* application instance */, JAXRSServerFactoryBean.class);
factory.setProvider(new OpenTracingFeature(tracer));
...
return factory.create(); |
Alternatively, you may rely on GlobalTracer to pass the tracer around, so in this case the OpenTracingFeature will pick it up from there, for example:
Code Block |
---|
|
@ApplicationPath( "/" )
public class CatalogApplication extends Application {
@Override
public Set<Object> getSingletons() {
return new HashSet<>(
Arrays.asList(
// No explicit Tracer instance is required, it will be picked off the GlobalTracer using get() method
new OpenTracingFeature()
)
);
}
} |
Once the span reporter and sampler are properly configured, all generated spans are going to be collected and available for analysis and/or visualization.