Brave JAX RS 2.0 Integration - hammock-project/hammock GitHub Wiki
Brave Integration is provided in a separate module. There's actually no core Hammock dependencies, so you could just use the JAR in your standard application without bringing in the rest of Hammock.
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>util-brave</artifactId>
<version>${hammock.version}</version>
</dependency>Brave integration requires you to provide two injection points:
- an instance of
Bravethat is configured based on your needs. - an instance of
SpanNameProviderthat can parse the underlying request.
You can use producers for both.
The integration assumes you can leverage a JAX-RS implementation that supports looking up Feature implementations as CDI beans. The default implementation is ws.ament.hammock.brave.SimpleExtension if you need to manually register it.
This is a simple integration that registers a log call for each span invocation.
@ApplicationScoped
public class BraveProducers {
@Produces
@Singleton
public Brave createBrave(Reporter<Span> reporter) {
return new Brave.Builder().reporter(reporter).build();
}
@Produces
@Singleton
public SpanNameProvider createSpanNameProvider() {
return h -> h.getUri().getPath();
}
}@ApplicationScoped
public class LoggingReporter implements Reporter<Span> {
private final Logger logger = LogManager.getLogger(LoggingReporter.class);
@Override
public void report(Span span) {
logger.info("Received request on span " + span.name + " request id "+span.idString());
}
}