Skip to content

pavolloffay/java-jaxrs

 
 

Repository files navigation

Build Status Released Version

OpenTracing JAX-RS Instrumentation

OpenTracing instrumentation for JAX-RS standard. It supports server and client request tracing.

Instrumentation by default adds set of standard tags and sets span operation name with HTTP method. This can be overridden by span decorators.

Tracing Server Requests

DynamicFeature dynamicFeafure = new ServerTracingDynamicFeature.Builder(tracer)
    .withDecorators(Arrays.asList(ServerSpanDecorator.HTTP_WILDCARD_PATH_OPERATION_NAME, 
                                  ServerSpanDecorator.STANDARD_TAGS))
    .build();
// register this in javax.ws.rs.core.Application

@GET
@Path("/hello")
@Traced(operationName = "helloRenamed") // optional, by default operation name is provided by ServerSpanDecorator
public Response hello(@BeanParam ServerSpanContext serverSpanContext) {
    /**
     * Some business logic
     */
    Span childSpan = tracer.buildSpan("businessOperation")
            .asChildOf(serverSpanContext.get())
            .start())
    childSpan.finish();

    return Response.status(Response.Status.OK).build();
}

Tracing Client Requests

Client client = ClientBuilder.newClient();
client.register(ClientTracingFeature.class);

Response response = jaxRsClient.target("http://localhost/endpoint")
    .request()
    .property(TracingProperties.CHILD_OF, parentSpanContext) // optional, by default new trace is started
    .property(TracingProperties.TRACING_DISABLED, false) // optional, by default false
    .get();

Development

./mvnw clean install

Release

Follow instructions in RELEASE

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 78.8%
  • Shell 14.5%
  • Batchfile 6.7%