Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 16dd8a3ea -> 4b88582c4
CXF-7247: Support tracing using latest Zipkin Brave 4.x release. Fixing parent scope propagation for wrapped calls (callables). Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4b88582c Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4b88582c Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4b88582c Branch: refs/heads/3.1.x-fixes Commit: 4b88582c45f1f6eb9d2170e403c94fd449a1ccd2 Parents: 16dd8a3 Author: reta <[email protected]> Authored: Fri Jun 2 19:09:33 2017 -0400 Committer: reta <[email protected]> Committed: Fri Jun 2 20:43:19 2017 -0400 ---------------------------------------------------------------------- .../samples/jax_rs/tracing_brave_osgi/README.txt | 19 ++++++------------- .../cxf/tracing/brave/BraveTracerContext.java | 14 ++++++++++++-- .../features/src/main/resources/features.xml | 4 ++++ .../jaxrs/tracing/brave/BraveTracingTest.java | 3 +++ 4 files changed, 25 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/4b88582c/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/README.txt ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/README.txt b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/README.txt index 2832d9e..1f88a59 100644 --- a/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/README.txt +++ b/distribution/src/main/release/samples/jax_rs/tracing_brave_osgi/README.txt @@ -5,20 +5,13 @@ The demo shows a basic usage of Brave/OpenZipkin distributed tracer with REST ba Web Services using JAX-RS 2.0 (JSR-339). The REST server provides the following services: -A RESTful catalog service is provided on URL http://localhost:9000/catalog - -A HTTP GET request to URL http://localhost:8181/cxf/catalog generates following -traces: - -A HTTP POST request to URL http://localhost:8181/cxf/catalog generates following -traces: - -A HTTP GET request to URL http://localhost:8181/cxf/catalog/<id> generates following -traces: - -A HTTP DELETE request to URL http://localhost:8181/cxf/catalog/<id> generates following -traces: +A RESTful catalog service is provided on URL http://localhost:9000/catalog with +following endpoints available: + GET http://localhost:8181/cxf/catalog + POST http://localhost:8181/cxf/catalog + GET http://localhost:8181/cxf/catalog/<id> + DELETE http://localhost:8181/cxf/catalog/<id> Building and running the demo using Maven --------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/4b88582c/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java ---------------------------------------------------------------------- diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java index d803c60..e4479cd 100644 --- a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java +++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java @@ -54,7 +54,7 @@ public class BraveTracerContext implements TracerContext { public <T> T continueSpan(final Traceable<T> traceable) throws Exception { SpanInScope scope = null; - if (tracer.currentSpan() != null && continuationSpan != null) { + if (tracer.currentSpan() == null && continuationSpan != null) { scope = tracer.withSpanInScope(continuationSpan); } @@ -76,10 +76,12 @@ public class BraveTracerContext implements TracerContext { } }; + // Carry over parent from the current thread + final Span parent = tracer.currentSpan(); return new Callable<T>() { @Override public T call() throws Exception { - try (TraceScope span = startSpan(description)) { + try (TraceScope span = newOrChildSpan(description, parent)) { return callable.call(); } } @@ -101,4 +103,12 @@ public class BraveTracerContext implements TracerContext { current.annotate(message); } } + + private TraceScope newOrChildSpan(final String description, final Span parent) { + if (parent == null) { + return new TraceScope(brave, tracer.newTrace().name(description).start()); + } else { + return new TraceScope(brave, tracer.newChild(parent.context()).name(description).start()); + } + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/4b88582c/osgi/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/osgi/karaf/features/src/main/resources/features.xml b/osgi/karaf/features/src/main/resources/features.xml index 6476129..166b470 100644 --- a/osgi/karaf/features/src/main/resources/features.xml +++ b/osgi/karaf/features/src/main/resources/features.xml @@ -241,6 +241,10 @@ <bundle start-level="35">mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/${cxf.jackson.version}</bundle> <bundle start-level="35">mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${cxf.jackson.version}</bundle> </feature> + <feature name="cxf-jsr-json" version="${project.version}"> + <bundle start-level="35">mvn:javax.json/javax.json-api/${cxf.json.api.version}</bundle> + <bundle start-level="35">mvn:org.apache.johnzon/johnzon-core/${cxf.johnzon.version}</bundle> + </feature> <feature name="cxf-tracing-brave" version="${project.version}"> <feature version="${project.version}">cxf-core</feature> <bundle start-level="10" dependency="true">mvn:com.google.code.findbugs/jsr305/${cxf.findbugs.version}</bundle> http://git-wip-us.apache.org/repos/asf/cxf/blob/4b88582c/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java ---------------------------------------------------------------------- diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java index 00861eb..85d4a17 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java @@ -195,6 +195,9 @@ public class BraveTracingTest extends AbstractBusClientServerTestBase { assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); assertThat(TestSpanReporter.getAllSpans().get(1).name, equalTo("get /bookstore/books/async")); assertThat(TestSpanReporter.getAllSpans().get(0).name, equalTo("processing books")); + assertThat(TestSpanReporter.getAllSpans().get(0).parentId, not(nullValue())); + assertThat(TestSpanReporter.getAllSpans().get(0).parentId, + equalTo(TestSpanReporter.getAllSpans().get(1).id)); assertThatTraceIsPresent(r, spanId); }
