Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump OT to 0.30.0 #36

Merged
merged 5 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 80 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,100 @@

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

Instrumentation by default adds a set of standard HTTP tags and as an operation name it uses a string defined in `@Path` annotation. Custom tags or operation name can be defined in span decorators.
Instrumentation by default adds a set of standard HTTP tags and as an operation name it uses a string defined in `@Path` annotation.
Custom tags or operation name can be defined in span decorators.

## Tracing Server Requests
By default OpenTracing provider is automatically discovered and registered. The only configuration that is required is to register a tracer instance: `GlobalTracer.register(tracer)` at application startup.
## Tracing server requests
By default OpenTracing provider is automatically discovered and registered.
The only configuration that is required is to register a tracer instance via `GlobalTracer.register(tracer)` at application startup.

### Custom configuration
Custom configuration is only required when using a different set of span decoratos.

Custom configuration
```java
// code sample from javax.ws.rs.core.Application#getSingletons();
DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(tracer)
.withDecorators(decorators)
.build();
singletons.add(tracing);
return singletons;
// code sample from javax.ws.rs.core.Application
public Set<Object> getSingletons() {
DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(tracer)
.withDecorators(decorators)
.build();

return Collections.singleton(tracing);
}

```

An example of traced REST endpoint:
```java
@GET
@Path("/hello")
@Traced(operationName = "helloRenamed") // optional, see javadoc
public Response hello(@BeanParam ServerSpanContext serverSpanContext) { // optional to get server span context
/**
* Some business logic
*/
Span childSpan = tracer.buildSpan("businessOperation")
.asChildOf(serverSpanContext.get())
.start())
childSpan.finish();

return Response.status(Response.Status.OK).build();
public Response hello(@BeanParam TracingContext tracingContext) { // optional to get server span context

// this span will be ChildOf of span representing server request processing, if it is not async, keep reading!
Span childSpan = tracer.buildSpan("businessOperation")
.start())

// business logic
childSpan.finish();

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

## Tracing Client Requests
#### Async handlers
In case of async handlers server span is not accessible via `tracer.activeSpan()`, however span context
can be obtained via `@BeanParam TracingContext tracingContext`. This object is injected as a handler param.

## Tracing client requests
```java
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();
Client client = ClientBuilder.newBuilder()
.reqister(ClientTracingFeature.class)
.build();

Response response = client.target("http://localhost/endpoint")
.request()
.property(TracingProperties.CHILD_OF, parentSpanContext) // optional, by default new parent is inferred from span source
.property(TracingProperties.TRACING_DISABLED, false) // optional, by default everything is traced
.get();
```

### Async
Async requests are executed in a different thread than when the client has been invoked, therefore
spans representing client requests are not connected to appropriate parent. To fix this JAX-RS client
has to use OpenTracing-aware [`ExecutorService`](https://github.com/opentracing-contrib/java-concurrent).

#### Jersey
```java
@ClientAsyncExecutor
public class DelegateExecutorServiceProvider implements ExecutorServiceProvider {

private final ExecutorService executorService;

public DelegateExecutorServiceProvider(ExecutorService executorService) {
this.executorService = executorService;
}

@Override
public ExecutorService getExecutorService() {
return executorService;
}

@Override
public void dispose(ExecutorService executorService) {
}
}

Client client = ClientBuilder.newBuilder()
.register(new DelegateExecutorServiceProvider(
new TracedExecutorService(Executors.newFixedThreadPool(8), tracer)))
...
```

#### RestEasy
```java
Client client = new ResteasyClientBuilder()
.asyncExecutor(new TracedExecutorService(Executors.newFixedThreadPool(8), tracer))
...
```

## Development
Expand All @@ -57,7 +108,6 @@ Response response = jaxRsClient.target("http://localhost/endpoint")
## Release
Follow instructions in [RELEASE](RELEASE.md)


[ci-img]: https://travis-ci.org/opentracing-contrib/java-jaxrs.svg?branch=master
[ci]: https://travis-ci.org/opentracing-contrib/java-jaxrs
[maven-img]: https://img.shields.io/maven-central/v/io.opentracing.contrib/opentracing-jaxrs2.svg?maxAge=2592000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.opentracing.contrib.jaxrs2.itest.cxf;

import io.opentracing.contrib.jaxrs2.itest.common.AbstractClientTest;
import java.util.concurrent.ExecutionException;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.junit.Test;

/**
* @author Pavol Loffay
Expand All @@ -12,4 +14,13 @@ public class ApacheCXFClientITest extends AbstractClientTest {
protected void initServletContext(ServletContextHandler context) {
ApacheCXFHelper.initServletContext(context);
}

/**
* Does not work because client spans are not connected to parent. Apache CXF does not allow
* to set custom ExecutorService
*/
@Test
@Override
public void testAsyncMultipleRequests() throws ExecutionException, InterruptedException {
}
}
2 changes: 1 addition & 1 deletion opentracing-jaxrs2-itest/auto-discovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>0.0.7-SNAPSHOT</version>
</parent>

<artifactId>auto-discovery</artifactId>
<artifactId>opentracing-jaxrs2-itest-auto-discovery</artifactId>

<dependencyManagement>
<dependencies>
Expand Down
Loading