Skip to content

Brave JAX RS 2.0 Integration

John D. Ament edited this page Aug 21, 2017 · 4 revisions

Brave Integration

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 Brave that is configured based on your needs.
  • an instance of SpanNameProvider that can parse the underlying request.

You can use producers for both.

Compatibility

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.

Example Integration

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());
    }
}
Clone this wiki locally