cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/3] cxf git commit: CXF-7247: Support tracing using latest Zipkin Brave 4.x release. Backporting from 3.2 (master) to 3.1 release branch.
Date Wed, 31 May 2017 18:11:41 GMT
http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveProvider.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveProvider.java
new file mode 100644
index 0000000..aaa4bf3
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveProvider.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.tracing.AbstractTracingProvider;
+import org.apache.cxf.tracing.brave.internal.HttpAdapterFactory;
+import org.apache.cxf.tracing.brave.internal.HttpAdapterFactory.Request;
+import org.apache.cxf.tracing.brave.internal.HttpAdapterFactory.Response;
+import org.apache.cxf.tracing.brave.internal.HttpServerAdapterFactory;
+
+import brave.Span;
+import brave.Tracer.SpanInScope;
+import brave.http.HttpServerAdapter;
+import brave.http.HttpServerHandler;
+import brave.http.HttpTracing;
+import brave.propagation.Propagation.Getter;
+
+public abstract class AbstractBraveProvider extends AbstractTracingProvider {
+    protected static final Logger LOG = LogUtils.getL7dLogger(AbstractBraveProvider.class);
+    protected static final String TRACE_SPAN = "org.apache.cxf.tracing.brave.span";
+
+    protected final HttpTracing brave;
+    
+    protected AbstractBraveProvider(final HttpTracing brave) {
+        this.brave = brave;
+    }
+
+    protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders,
+            URI uri, String method) {
+
+        final Request request = HttpAdapterFactory.request(requestHeaders, uri, method);
+        final HttpServerAdapter<Request, ?> adapter = HttpServerAdapterFactory.create(request);
+        
+        @SuppressWarnings("unchecked")
+        final HttpServerHandler<Request, ?> handler = HttpServerHandler.create(brave, adapter);
+        
+        Span span = handler.handleReceive(
+            brave
+                .tracing()
+                .propagation()
+                .extractor(
+                    new Getter<Request, String>() {
+                        @Override
+                        public String get(Request carrier, String key) {
+                            return adapter.requestHeader(carrier, key);
+                        }
+                    }
+                ), 
+            request);
+        
+        // If the service resource is using asynchronous processing mode, the trace
+        // scope will be closed in another thread and as such should be detached.
+        SpanInScope scope = null;
+        if (isAsyncResponse() && span != null) {
+           // Do not modify the current context span
+            propagateContinuationSpan(span);
+        } else if (span != null && !span.isNoop()) {
+            scope = brave.tracing().tracer().withSpanInScope(span);
+        }
+
+        return new TraceScopeHolder<TraceScope>(new TraceScope(span, scope), scope == null /* detached */);
+    }
+
+    protected void stopTraceSpan(final Map<String, List<String>> requestHeaders,
+                                 final Map<String, List<Object>> responseHeaders,
+                                 final int responseStatus,
+                                 final TraceScopeHolder<TraceScope> holder) {
+
+        // Transfer tracing headers into the response headers
+        for (final String key: brave.tracing().propagation().keys()) {
+            transferRequestHeader(requestHeaders, responseHeaders, key);
+        }
+
+        if (holder == null) {
+            return;
+        }
+
+        final TraceScope scope = holder.getScope();
+        if (scope != null) {
+            try {
+                // If the service resource is using asynchronous processing mode, the trace
+                // scope has been created in another thread and should be re-attached to the current
+                // one.
+                if (holder.isDetached()) {
+                    brave.tracing().tracer().joinSpan(scope.getSpan().context());
+                }
+    
+                final Response response = HttpAdapterFactory.response(responseStatus);
+                final HttpServerAdapter<?, Response> adapter = HttpServerAdapterFactory.create(response);
+                
+                @SuppressWarnings("unchecked")
+                final HttpServerHandler<?, Response> handler = HttpServerHandler.create(brave, adapter);
+                handler.handleSend(response, null, scope.getSpan());
+            } finally {
+                scope.close();
+            }
+        }
+    }
+
+    protected boolean isAsyncResponse() {
+        return !PhaseInterceptorChain.getCurrentMessage().getExchange().isSynchronous();
+    }
+
+    private void propagateContinuationSpan(final Span continuationScope) {
+        PhaseInterceptorChain.getCurrentMessage().put(Span.class, continuationScope);
+    }
+
+    private void transferRequestHeader(final Map<String, List<String>> requestHeaders,
+            final Map<String, List<Object>> responseHeaders, final String header) {
+        if (requestHeaders.containsKey(header)) {
+            responseHeaders.put(header, CastUtils.cast(requestHeaders.get(header)));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientFeature.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientFeature.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientFeature.java
new file mode 100644
index 0000000..7e4a7c6
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientFeature.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.annotations.Provider;
+import org.apache.cxf.annotations.Provider.Scope;
+import org.apache.cxf.annotations.Provider.Type;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+
+import brave.Tracing;
+import brave.http.HttpTracing;
+
+@NoJSR250Annotations
+@Provider(value = Type.Feature, scope = Scope.Client)
+public class BraveClientFeature extends AbstractFeature {
+    private BraveClientStartInterceptor out;
+    private BraveClientStopInterceptor in;
+
+    public BraveClientFeature(final Tracing tracing) {
+        this(
+          HttpTracing
+              .newBuilder(tracing)
+              .clientParser(new HttpClientSpanParser())
+              .build()
+         );
+    }
+    
+    public BraveClientFeature(HttpTracing brave) {
+        out = new BraveClientStartInterceptor(brave);
+        in = new BraveClientStopInterceptor(brave);
+    }
+
+    @Override
+    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+        provider.getInInterceptors().add(in);
+        provider.getOutInterceptors().add(out);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStartInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStartInterceptor.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStartInterceptor.java
new file mode 100644
index 0000000..34e944d
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStartInterceptor.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.tracing.brave.AbstractBraveInterceptor.ParsedMessage;
+
+import brave.http.HttpTracing;
+
+public class BraveClientStartInterceptor extends AbstractBraveClientInterceptor {
+    public BraveClientStartInterceptor(final HttpTracing brave) {
+        this(Phase.PRE_STREAM, brave);
+    }
+
+    public BraveClientStartInterceptor(final String phase, final HttpTracing brave) {
+        super(phase, brave);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        final ParsedMessage parsed = new ParsedMessage(message);
+
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(parsed.getHeaders(),
+            parsed.getUri(), parsed.getHttpMethod());
+
+        if (holder != null) {
+            message.getExchange().put(TRACE_SPAN, holder);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStopInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStopInterceptor.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStopInterceptor.java
new file mode 100644
index 0000000..ebca21a
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveClientStopInterceptor.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+import brave.http.HttpTracing;
+
+public class BraveClientStopInterceptor extends AbstractBraveClientInterceptor {
+    public BraveClientStopInterceptor(final HttpTracing brave) {
+        this(Phase.RECEIVE, brave);
+    }
+
+    public BraveClientStopInterceptor(final String phase, final HttpTracing brave) {
+        super(phase, brave);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        @SuppressWarnings("unchecked")
+        final TraceScopeHolder<TraceScope> holder =
+            (TraceScopeHolder<TraceScope>)message.getExchange().get(TRACE_SPAN);
+
+        Integer responseCode = (Integer)message.get(Message.RESPONSE_CODE);
+        if (responseCode == null) {
+            responseCode = 200;
+        }
+
+        super.stopTraceSpan(holder, responseCode);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveFeature.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveFeature.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveFeature.java
new file mode 100644
index 0000000..5f1e010
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveFeature.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.util.UUID;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.annotations.Provider;
+import org.apache.cxf.annotations.Provider.Scope;
+import org.apache.cxf.annotations.Provider.Type;
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.InterceptorProvider;
+
+import brave.Tracing;
+import brave.http.HttpTracing;
+
+@NoJSR250Annotations
+@Provider(value = Type.Feature, scope = Scope.Server)
+public class BraveFeature extends AbstractFeature {
+    private BraveStartInterceptor in;
+    private BraveStopInterceptor out;
+
+    public BraveFeature() {
+        this("cxf-svc-" + UUID.randomUUID().toString());
+    }
+
+    public BraveFeature(final String name) {
+        this(
+            HttpTracing
+                .newBuilder(Tracing.newBuilder().localServiceName(name).build())
+                .serverParser(new HttpServerSpanParser())
+                .build()
+        );
+    }
+    
+    public BraveFeature(final Tracing tracing) {
+        this(
+          HttpTracing
+              .newBuilder(tracing)
+              .serverParser(new HttpServerSpanParser())
+              .build()
+         );
+    }
+
+    public BraveFeature(HttpTracing brave) {
+        in = new BraveStartInterceptor(brave);
+        out = new BraveStopInterceptor(brave);
+    }
+
+    @Override
+    protected void initializeProvider(InterceptorProvider provider, Bus bus) {
+        provider.getInInterceptors().add(in);
+        provider.getInFaultInterceptors().add(in);
+
+        provider.getOutInterceptors().add(out);
+        provider.getOutFaultInterceptors().add(out);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStartInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStartInterceptor.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStartInterceptor.java
new file mode 100644
index 0000000..4df7c7e
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStartInterceptor.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+
+import brave.http.HttpTracing;
+
+@NoJSR250Annotations
+public class BraveStartInterceptor extends AbstractBraveInterceptor {
+    public BraveStartInterceptor(HttpTracing brave) {
+        super(Phase.PRE_INVOKE, brave);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        final ParsedMessage parsed = new ParsedMessage(message);
+
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(parsed.getHeaders(),
+            parsed.getUri(), parsed.getHttpMethod());
+
+        if (holder != null) {
+            message.getExchange().put(TRACE_SPAN, holder);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStopInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStopInterceptor.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStopInterceptor.java
new file mode 100644
index 0000000..75d1d3a
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveStopInterceptor.java
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.phase.Phase;
+
+import brave.http.HttpTracing;
+
+@NoJSR250Annotations
+public class BraveStopInterceptor extends AbstractBraveInterceptor {
+    public BraveStopInterceptor(final HttpTracing brave) {
+        super(Phase.PRE_MARSHAL, brave);
+    }
+
+    @Override
+    public void handleMessage(Message message) throws Fault {
+        Map<String, List<Object>> responseHeaders = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+
+        if (responseHeaders == null) {
+            responseHeaders = new HashMap<>();
+            message.put(Message.PROTOCOL_HEADERS, responseHeaders);
+        }
+
+        boolean isRequestor = MessageUtils.isRequestor(message);
+        Message requestMessage = isRequestor ? message.getExchange().getOutMessage()
+            : message.getExchange().getInMessage();
+        Map<String, List<String>> requestHeaders =
+            CastUtils.cast((Map<?, ?>)requestMessage.get(Message.PROTOCOL_HEADERS));
+
+        @SuppressWarnings("unchecked")
+        final TraceScopeHolder<TraceScope> holder =
+            (TraceScopeHolder<TraceScope>)message.getExchange().get(TRACE_SPAN);
+
+        Integer responseCode = (Integer)message.get(Message.RESPONSE_CODE);
+        if (responseCode == null) {
+            responseCode = 200;
+        }
+
+        super.stopTraceSpan(requestHeaders, responseHeaders, responseCode, holder);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/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
new file mode 100644
index 0000000..d803c60
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/BraveTracerContext.java
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.util.concurrent.Callable;
+
+import org.apache.cxf.tracing.Traceable;
+import org.apache.cxf.tracing.TracerContext;
+
+import brave.Span;
+import brave.Tracer;
+import brave.Tracer.SpanInScope;
+import brave.http.HttpTracing;
+
+public class BraveTracerContext implements TracerContext {
+    private final HttpTracing brave;
+    private final Tracer tracer;
+    private final Span continuationSpan;
+
+    public BraveTracerContext(final HttpTracing brave) {
+        this(brave, null);
+    }
+
+    public BraveTracerContext(final HttpTracing brave, final 
+            Span continuationSpan) {
+        this.brave = brave;
+        this.tracer = brave.tracing().tracer();
+        this.continuationSpan = continuationSpan;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public TraceScope startSpan(final String description) {
+        return new TraceScope(brave, tracer.nextSpan().name(description).start());
+    }
+
+    @Override
+    public <T> T continueSpan(final Traceable<T> traceable) throws Exception {
+        SpanInScope scope = null;
+        
+        if (tracer.currentSpan() != null && continuationSpan != null) {
+            scope = tracer.withSpanInScope(continuationSpan);
+        }
+
+        try {
+            return traceable.call(new BraveTracerContext(brave));
+        } finally {
+            if (continuationSpan != null && scope != null) {
+                scope.close();
+            }
+        }
+    }
+
+    @Override
+    public <T> Callable<T> wrap(final String description, final Traceable<T> traceable) {
+        final Callable<T> callable = new Callable<T>() {
+            @Override
+            public T call() throws Exception {
+                return traceable.call(new BraveTracerContext(brave));
+            }
+        };
+
+        return new Callable<T>() {
+            @Override
+            public T call() throws Exception {
+                try (TraceScope span = startSpan(description)) {
+                    return callable.call();
+                }
+            }
+        };
+    }
+
+    @Override
+    public void annotate(String key, String value) {
+        final Span current = tracer.currentSpan();
+        if (current != null) {
+            current.tag(key, value);
+        }
+    }
+
+    @Override
+    public void timeline(String message) {
+        final Span current = tracer.currentSpan();
+        if (current != null) {
+            current.annotate(message);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientSpanParser.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientSpanParser.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientSpanParser.java
new file mode 100644
index 0000000..a139e06
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientSpanParser.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.common.util.StringUtils;
+
+import brave.http.HttpAdapter;
+import brave.http.HttpClientParser;
+
+public class HttpClientSpanParser extends HttpClientParser {
+    @Override
+    protected <Req> String spanName(HttpAdapter<Req, ?> adapter, Req request) {
+        return buildSpanDescription(adapter.url(request), adapter.method(request));
+    }
+
+    private String buildSpanDescription(final String path, final String method) {
+        if (StringUtils.isEmpty(method)) {
+            return path;
+        } else {
+            return method + " " + path;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpServerSpanParser.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpServerSpanParser.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpServerSpanParser.java
new file mode 100644
index 0000000..dbd477e
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpServerSpanParser.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import org.apache.cxf.common.util.StringUtils;
+
+import brave.http.HttpAdapter;
+import brave.http.HttpServerParser;
+
+public class HttpServerSpanParser extends HttpServerParser {
+    @Override
+    protected <Req> String spanName(HttpAdapter<Req, ?> adapter, Req request) {
+        return buildSpanDescription(adapter.path(request), adapter.method(request));
+    }
+
+    private String buildSpanDescription(final String path, final String method) {
+        if (StringUtils.isEmpty(method)) {
+            return path;
+        } else {
+            return method + " " + path;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/TraceScope.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/TraceScope.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/TraceScope.java
new file mode 100644
index 0000000..27b8deb
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/TraceScope.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.io.Closeable;
+
+import brave.Span;
+import brave.Tracer.SpanInScope;
+import brave.http.HttpTracing;
+
+public class TraceScope implements Closeable {
+    private final Span span;
+    private final SpanInScope scope;
+
+    TraceScope(final HttpTracing brave, final Span span) {
+        this(span, brave.tracing().tracer().withSpanInScope(span));
+    }
+
+    TraceScope(final Span span, final SpanInScope scope) {
+        this.span = span;
+        this.scope = scope;
+    }
+    
+    public Span getSpan() {
+        return span;
+    }
+
+    @Override
+    public void close() {
+        span.finish();
+        if (scope != null) {
+            scope.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpAdapterFactory.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpAdapterFactory.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpAdapterFactory.java
new file mode 100644
index 0000000..d855599
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpAdapterFactory.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.internal;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+public abstract class HttpAdapterFactory {
+    public static final class Request {
+        private final Map<String, List<String>> headers;
+        private final URI uri;
+        private final String method;
+        
+        Request(Map<String, List<String>> headers, URI uri, String method) {
+            this.headers = headers;
+            this.uri = uri;
+            this.method = method;
+        }
+        
+        Map<String, List<String>> headers() {
+            return headers;
+        }
+        
+        URI uri() {
+            return uri;
+        }
+        
+        String method() {
+            return method;
+        }
+    }
+    
+    public static final class Response {
+        private final Integer status;
+        
+        Response(Integer status) {
+            this.status = status;
+        }
+        
+        Integer status() {
+            return status;
+        }
+    }
+    
+    public static Request request(Map<String, List<String>> headers, URI uri, String method) {
+        return new Request(headers, uri, method);
+    }
+    
+    public static Response response(Integer status) {
+        return new Response(status);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpClientAdapterFactory.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpClientAdapterFactory.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpClientAdapterFactory.java
new file mode 100644
index 0000000..68b4b7c
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpClientAdapterFactory.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.internal;
+
+import java.util.List;
+
+import brave.http.HttpClientAdapter;
+
+public abstract class HttpClientAdapterFactory extends HttpAdapterFactory {
+    public static HttpClientAdapter<Request, Response> create(Request request) {
+        return new HttpClientAdapter<Request, Response>() {
+            @Override 
+            public String method(Request request) {
+                return request.method();
+            }
+    
+            @Override 
+            public String path(Request request) {
+                return request.uri().getPath();
+            }
+    
+            @Override 
+            public String url(Request request) {
+                return request.uri().toString();
+            }
+    
+            @Override 
+            public String requestHeader(Request request, String name) {
+                List<String> value = request.headers().get(name);
+    
+                if (value != null && !value.isEmpty()) {
+                    return value.get(0);
+                }
+    
+                return null;
+            }
+    
+            @Override 
+            public Integer statusCode(Response response) {
+                throw new UnsupportedOperationException("The operation is not supported for request adapter");
+            }
+        };
+    }
+    
+    public static HttpClientAdapter<Request, Response> create(Response response) {
+        return new HttpClientAdapter<Request, Response>() {
+            @Override 
+            public String method(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String path(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String url(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String requestHeader(Request request, String name) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public Integer statusCode(Response response) {
+                return response.status();
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpServerAdapterFactory.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpServerAdapterFactory.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpServerAdapterFactory.java
new file mode 100644
index 0000000..6939d0a
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/internal/HttpServerAdapterFactory.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.internal;
+
+import java.util.List;
+
+import brave.http.HttpServerAdapter;
+
+public abstract class HttpServerAdapterFactory extends HttpAdapterFactory {
+    public static HttpServerAdapter<Request, Response> create(Request request) {
+        return new HttpServerAdapter<Request, Response>() {
+            @Override 
+            public String method(Request request) {
+                return request.method();
+            }
+    
+            @Override 
+            public String path(Request request) {
+                return request.uri().getPath();
+            }
+    
+            @Override 
+            public String url(Request request) {
+                return request.uri().toString();
+            }
+    
+            @Override 
+            public String requestHeader(Request request, String name) {
+                List<String> value = request.headers().get(name);
+    
+                if (value != null && !value.isEmpty()) {
+                    return value.get(0);
+                }
+    
+                return null;
+            }
+    
+            @Override 
+            public Integer statusCode(Response response) {
+                throw new UnsupportedOperationException("The operation is not supported for request adapter");
+            }
+        };
+    }
+    
+    public static HttpServerAdapter<Request, Response> create(Response response) {
+        return new HttpServerAdapter<Request, Response>() {
+            @Override 
+            public String method(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String path(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String url(Request request) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public String requestHeader(Request request, String name) {
+                throw new UnsupportedOperationException("The operation is not supported for response adapter");
+            }
+    
+            @Override 
+            public Integer statusCode(Response response) {
+                return response.status();
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveClientProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveClientProvider.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveClientProvider.java
new file mode 100644
index 0000000..e08553a
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveClientProvider.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.jaxrs;
+
+import java.io.IOException;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.tracing.brave.AbstractBraveClientProvider;
+import org.apache.cxf.tracing.brave.HttpClientSpanParser;
+import org.apache.cxf.tracing.brave.TraceScope;
+
+import brave.Tracing;
+import brave.http.HttpTracing;
+
+@Provider
+public class BraveClientProvider extends AbstractBraveClientProvider
+        implements ClientRequestFilter, ClientResponseFilter {
+
+    public BraveClientProvider(final Tracing brave) {
+        this(
+            HttpTracing
+                .newBuilder(brave)
+                .clientParser(new HttpClientSpanParser())
+                .build()
+        );
+    }
+
+    public BraveClientProvider(final HttpTracing brave) {
+        super(brave);
+    }
+
+    @Override
+    public void filter(final ClientRequestContext requestContext) throws IOException {
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(),
+            requestContext.getUri(), requestContext.getMethod());
+
+        if (holder != null) {
+            requestContext.setProperty(TRACE_SPAN, holder);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void filter(final ClientRequestContext requestContext,
+            final ClientResponseContext responseContext) throws IOException {
+        final TraceScopeHolder<TraceScope> holder =
+            (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN);
+        super.stopTraceSpan(holder, responseContext.getStatus());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveContextProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveContextProvider.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveContextProvider.java
new file mode 100644
index 0000000..1f67112
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveContextProvider.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.jaxrs;
+
+import org.apache.cxf.jaxrs.ext.ContextProvider;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.tracing.TracerContext;
+import org.apache.cxf.tracing.brave.BraveTracerContext;
+
+import brave.Span;
+import brave.http.HttpTracing;
+
+public class BraveContextProvider implements ContextProvider< TracerContext > {
+    private final HttpTracing brave;
+
+    public BraveContextProvider(final HttpTracing brave) {
+        this.brave = brave;
+    }
+
+    @Override
+    public TracerContext createContext(final Message message) {
+        // Check if there is a server span passed along with the message
+        final Span continuationSpan = message.get(Span.class);
+
+        // If server span is already present, let us check if it is detached
+        // (asynchronous invocation)
+        if (continuationSpan != null) {
+            return new BraveTracerContext(brave, continuationSpan);
+        }
+
+        return new BraveTracerContext(brave);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveFeature.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveFeature.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveFeature.java
new file mode 100644
index 0000000..6652604
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveFeature.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.jaxrs;
+
+import java.util.UUID;
+
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.tracing.brave.HttpServerSpanParser;
+
+import brave.Tracing;
+import brave.http.HttpTracing;
+
+@Provider
+public class BraveFeature implements Feature {
+    private final HttpTracing brave;
+
+    public BraveFeature() {
+        this("cxf-svc-" + UUID.randomUUID().toString());
+    }
+
+    public BraveFeature(final String name) {
+        this(
+            HttpTracing
+                .newBuilder(Tracing.newBuilder().localServiceName(name).build())
+                .serverParser(new HttpServerSpanParser())
+                .build()
+        );
+    }
+
+    public BraveFeature(final Tracing tracing) {
+        this(
+          HttpTracing
+              .newBuilder(tracing)
+              .serverParser(new HttpServerSpanParser())
+              .build()
+         );
+    }
+
+    public BraveFeature(final HttpTracing brave) {
+        this.brave = brave;
+    }
+
+    @Override
+    public boolean configure(FeatureContext context) {
+        context.register(new BraveProvider(brave));
+        context.register(new BraveContextProvider(brave));
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveProvider.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveProvider.java
new file mode 100644
index 0000000..7a21626
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/jaxrs/BraveProvider.java
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave.jaxrs;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.tracing.brave.AbstractBraveProvider;
+import org.apache.cxf.tracing.brave.TraceScope;
+
+import brave.http.HttpTracing;
+
+@Provider
+public class BraveProvider extends AbstractBraveProvider
+    implements ContainerRequestFilter, ContainerResponseFilter {
+    @Context
+    private ResourceInfo resourceInfo;
+
+    public BraveProvider(final HttpTracing brave) {
+        super(brave);
+    }
+
+    @Override
+    public void filter(final ContainerRequestContext requestContext) throws IOException {
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getHeaders(),
+            requestContext.getUriInfo().getRequestUri(), requestContext.getMethod());
+
+        if (holder != null) {
+            requestContext.setProperty(TRACE_SPAN, holder);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void filter(final ContainerRequestContext requestContext,
+            final ContainerResponseContext responseContext) throws IOException {
+        super.stopTraceSpan(requestContext.getHeaders(), responseContext.getHeaders(),
+            responseContext.getStatus(), (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN));
+    }
+
+    @Override
+    protected boolean isAsyncResponse() {
+        for (final Annotation[] annotations: resourceInfo.getResourceMethod().getParameterAnnotations()) {
+            for (final Annotation annotation: annotations) {
+                if (annotation.annotationType().equals(Suspended.class)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/BraveTraceTest.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/BraveTraceTest.java b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/BraveTraceTest.java
new file mode 100644
index 0000000..b36fc47
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/BraveTraceTest.java
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import brave.Tracing;
+import zipkin.Span;
+import zipkin.reporter.Reporter;
+
+public class BraveTraceTest {
+
+    private static final String ADDRESS = "http://localhost:8182";
+    private Server server;
+    private BraveFeature logging;
+    private BraveClientFeature clientLogging;
+    private Localreporter localReporter;
+
+    @Before
+    public void startServer() {
+        localReporter = new Localreporter();
+        logging = createLoggingFeature(localReporter);
+        clientLogging = createClientLoggingFeature(localReporter);
+        server = createServer(logging);
+    }
+
+    @Test
+    public void testMyService() {
+        MyService myService = createProxy(clientLogging);
+        myService.echo("test");
+        for (Span span : localReporter.spans) {
+            System.out.println(span);
+        }
+        Assert.assertEquals(2, localReporter.spans.size());
+
+    }
+
+    @After
+    public void stopServer() {
+        server.destroy();
+    }
+
+    private static Server createServer(Feature logging) {
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+        factory.setAddress(ADDRESS);
+        factory.setServiceBean(new MyServiceImpl());
+        factory.setFeatures(Arrays.asList(logging));
+        return factory.create();
+    }
+
+    private static MyService createProxy(Feature trace) {
+        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+        factory.setServiceClass(MyService.class);
+        factory.setAddress(ADDRESS);
+        factory.setFeatures(Arrays.asList(trace));
+        return (MyService)factory.create();
+    }
+
+    private static BraveFeature createLoggingFeature(Reporter<Span> reporter) {
+        Tracing brave = Tracing.newBuilder().localServiceName("myservice").reporter(reporter).build();
+        return new BraveFeature(brave);
+    }
+
+    private static BraveClientFeature createClientLoggingFeature(Reporter<Span> reporter) {
+        Tracing brave = Tracing.newBuilder().localServiceName("myservice").reporter(reporter).build();
+        return new BraveClientFeature(brave);
+    }
+
+    static final class Localreporter implements Reporter<Span> {
+        List<Span> spans = new ArrayList<>();
+
+        @Override
+        public void report(Span span) {
+            spans.add(span);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyService.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyService.java b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyService.java
new file mode 100644
index 0000000..77dc709
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyService.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+import javax.jws.WebService;
+
+@WebService
+public interface MyService {
+    String echo(String msg);
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyServiceImpl.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyServiceImpl.java b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyServiceImpl.java
new file mode 100644
index 0000000..594e8c7
--- /dev/null
+++ b/integration/tracing/tracing-brave/src/test/java/org/apache/cxf/tracing/brave/MyServiceImpl.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tracing.brave;
+
+public class MyServiceImpl implements MyService {
+
+    @Override
+    public String echo(String msg) {
+        return msg;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/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 7106619..6476129 100644
--- a/osgi/karaf/features/src/main/resources/features.xml
+++ b/osgi/karaf/features/src/main/resources/features.xml
@@ -241,6 +241,15 @@
         <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-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>
+        <bundle start-level="35">mvn:io.zipkin.java/zipkin/${cxf.brave.zipkin.version}</bundle>
+        <bundle start-level="35">mvn:io.zipkin.reporter/zipkin-reporter/${cxf.brave.reporter.version}</bundle>
+        <bundle start-level="35">mvn:io.zipkin.brave/brave/${cxf.brave.version}</bundle>
+        <bundle start-level="35">mvn:io.zipkin.brave/brave-instrumentation-http/${cxf.brave.version}</bundle>
+        <bundle start-level="40">mvn:org.apache.cxf/cxf-integration-tracing-brave/${project.version}</bundle>
+    </feature>
     <feature name="cxf-rs-description-swagger2" version="${project.version}" resolver="(obr)">
         <feature version="${project.version}">cxf-jaxrs</feature>
         <feature version="${project.version}">cxf-jackson</feature>

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index e4d63ba..be1f265 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -178,6 +178,7 @@
         <cxf.osgi.validation.api.version>1.1.0</cxf.osgi.validation.api.version>
         <cxf.hibernate.validator.version>5.2.2.Final</cxf.hibernate.validator.version>
         <cxf.glassfish.json.version>1.0.4</cxf.glassfish.json.version>
+        <cxf.johnzon.version>1.0.0</cxf.johnzon.version>
         <cxf.javax.el.version>3.0.0</cxf.javax.el.version>
         <!-- various OSGi related versions -->
         <cxf.aries.version>1.0.0</cxf.aries.version>
@@ -215,6 +216,10 @@
         <cxf.tika.version>1.14</cxf.tika.version>
         <cxf.jexl.version>2.1.1</cxf.jexl.version>
         <cxf.htrace.version>4.0.1-incubating</cxf.htrace.version>
+        <cxf.brave.version>4.3.1</cxf.brave.version>
+        <cxf.brave.zipkin.version>1.24.0</cxf.brave.zipkin.version>
+        <cxf.brave.reporter.version>0.9.0</cxf.brave.reporter.version>
+        <cxf.findbugs.version>3.0.2</cxf.findbugs.version>
         <cxf.checkstyle.extension />
         <cxf.jaxb.context.class />
         <cxf.jaxb.context.class.property>none</cxf.jaxb.context.class.property>
@@ -952,6 +957,12 @@
                 <optional>true</optional>
             </dependency>
             <dependency>
+                <groupId>org.apache.johnzon</groupId>
+                <artifactId>johnzon-core</artifactId>
+                <version>${cxf.johnzon.version}</version>
+                <optional>true</optional>
+            </dependency>
+            <dependency>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-jdk14</artifactId>
                 <version>${cxf.slf4j.version}</version>
@@ -1907,6 +1918,16 @@
                 <version>${cxf.htrace.version}</version>
             </dependency>
             <dependency>
+                 <groupId>io.zipkin.brave</groupId>
+                 <artifactId>brave</artifactId>
+                 <version>${cxf.brave.version}</version>
+            </dependency>
+            <dependency>
+                 <groupId>io.zipkin.brave</groupId>
+                 <artifactId>brave-instrumentation-http</artifactId>
+                 <version>${cxf.brave.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.apache.wss4j</groupId>
                 <artifactId>wss4j-ws-security-dom</artifactId>
                 <version>${cxf.wss4j.version}</version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/systests/tracing/pom.xml
----------------------------------------------------------------------
diff --git a/systests/tracing/pom.xml b/systests/tracing/pom.xml
index 4e72744..6e68d7f 100644
--- a/systests/tracing/pom.xml
+++ b/systests/tracing/pom.xml
@@ -65,6 +65,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-features-logging</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
             <version>${project.version}</version>
         </dependency>
@@ -85,14 +90,13 @@
         </dependency>                
         <dependency>
             <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-testutils</artifactId>
+            <artifactId>cxf-integration-tracing-brave</artifactId>
             <version>${project.version}</version>
-            <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>javax.annotation</groupId>
-            <artifactId>jsr250-api</artifactId>
-            <version>1.0</version>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-testutils</artifactId>
+            <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReporter.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReporter.java b/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReporter.java
new file mode 100644
index 0000000..d60b633
--- /dev/null
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReporter.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import zipkin.Span;
+import zipkin.reporter.Reporter;
+
+public class TestSpanReporter implements Reporter<Span> {
+    private static List<Span> spans = new ArrayList<>();
+
+    @Override
+    public void report(Span span) {
+        spans.add(span);
+    }
+
+    public static List<Span> getAllSpans() {
+        return spans;
+    }
+
+    public static void clear() {
+        spans.clear();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/systests/tracing/src/test/java/org/apache/cxf/systest/brave/BraveTestSupport.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/BraveTestSupport.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/BraveTestSupport.java
new file mode 100644
index 0000000..c44c9e8
--- /dev/null
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/BraveTestSupport.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.brave;
+
+public abstract class BraveTestSupport {
+    public static final String TRACE_ID_NAME = "X-B3-TraceId";
+    public static final String SPAN_ID_NAME = "X-B3-SpanId";
+    public static final String PARENT_SPAN_ID_NAME = "X-B3-ParentSpanId";
+    public static final String SAMPLED_NAME = "X-B3-Sampled";
+    
+    public static class SpanId {
+        private long traceId;
+        private long spanId;
+        private Long parentId;
+        private boolean sampled;
+         
+        public SpanId traceId(long id) {
+            this.traceId = id;
+            return this;
+        }
+
+        public SpanId parentId(Long id) {
+            this.parentId = id;
+            return this;
+        }
+
+        public SpanId spanId(long id) {
+            this.spanId = id;
+            return this;
+        }
+        
+        public SpanId sampled(boolean s) {
+            this.sampled = s;
+            return this;
+        }
+        
+        public long traceId() {
+            return traceId;
+        }
+        
+        public long spanId() {
+            return spanId;
+        }
+        
+        public Long parentId() {
+            return parentId;
+        }
+        
+        public boolean sampled() {
+            return sampled;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bcce9c6/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/BookStore.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/BookStore.java
index 0c7f691..4942020 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/BookStore.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/BookStore.java
@@ -18,12 +18,15 @@
  */
 package org.apache.cxf.systest.jaxrs.tracing;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.PUT;
@@ -39,18 +42,17 @@ import javax.ws.rs.core.Response;
 import org.apache.cxf.systest.Book;
 import org.apache.cxf.tracing.Traceable;
 import org.apache.cxf.tracing.TracerContext;
-import org.apache.htrace.core.TraceScope;
 
 @Path("/bookstore/")
-public class BookStore {
+public class BookStore<T extends Closeable> {
     @Context private TracerContext tracer;
     private ExecutorService executor = Executors.newSingleThreadExecutor();
         
     @GET
     @Path("/books")
     @Produces(MediaType.APPLICATION_JSON)
-    public Collection< Book > getBooks() {
-        try (TraceScope span =  tracer.startSpan("Get Books")) {
+    public Collection< Book > getBooks() throws IOException {
+        try (T span = tracer.startSpan("Get Books")) {
             return Arrays.asList(
                 new Book("Apache CXF in Action", UUID.randomUUID().toString()),
                 new Book("Mastering Apache CXF", UUID.randomUUID().toString())
@@ -144,8 +146,8 @@ public class BookStore {
     @PUT
     @Path("/process")
     @Produces(MediaType.APPLICATION_JSON)
-    public Response processBooks() {
-        executor.submit(
+    public Response processBooks() throws InterruptedException {
+        final Future<Void> future = executor.submit(
             tracer.wrap("Processing books", new Traceable<Void>() {
                 @Override
                 public Void call(final TracerContext context) throws Exception {
@@ -155,6 +157,11 @@ public class BookStore {
             })
         );
         
+        if (!future.isDone()) {
+            // Just give it some time to have trace finished 
+            Thread.sleep(20);
+        }
+
         return Response.ok().build();
     }
 }


Mime
View raw message