cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: CXF-6643: Upgraded Apache HTrace to 4.0 release branch
Date Thu, 15 Oct 2015 02:22:34 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f60dca758 -> c5c21d5b6


CXF-6643: Upgraded Apache HTrace to 4.0 release branch


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c5c21d5b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c5c21d5b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c5c21d5b

Branch: refs/heads/master
Commit: c5c21d5b61fbd57e79f0bf39fa56ef9814c417fd
Parents: f60dca7
Author: reta <drreta@gmail.com>
Authored: Wed Oct 14 22:22:13 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Wed Oct 14 22:22:13 2015 -0400

----------------------------------------------------------------------
 .../java/demo/jaxrs/tracing/client/Client.java  | 20 ++--
 .../tracing/conf/TracingConfiguration.java      |  4 +-
 .../tracing/server/CatalogApplication.java      | 11 ++-
 .../htrace/AbstractHTraceClientInterceptor.java |  6 +-
 .../htrace/AbstractHTraceClientProvider.java    | 51 ++++++-----
 .../htrace/AbstractHTraceInterceptor.java       |  6 +-
 .../tracing/htrace/AbstractHTraceProvider.java  | 71 +++++++--------
 .../htrace/HTraceClientStartInterceptor.java    | 22 +++--
 .../htrace/HTraceClientStopInterceptor.java     |  9 +-
 .../tracing/htrace/HTraceStartInterceptor.java  | 18 ++--
 .../tracing/htrace/HTraceStopInterceptor.java   |  8 +-
 .../cxf/tracing/htrace/HTraceTracerContext.java | 64 ++++++-------
 .../htrace/jaxrs/HTraceClientProvider.java      | 25 +++--
 .../htrace/jaxrs/HTraceContextProvider.java     | 19 ++--
 .../cxf/tracing/htrace/jaxrs/HTraceFeature.java | 36 ++++----
 .../tracing/htrace/jaxrs/HTraceProvider.java    | 23 ++---
 parent/pom.xml                                  |  2 +-
 .../cxf/tracing/AbstractTracingProvider.java    | 25 ++++-
 .../org/apache/cxf/tracing/TracerContext.java   |  8 +-
 .../org/apache/cxf/tracing/TracerHeaders.java   |  3 -
 .../apache/cxf/systest/TestSpanReceiver.java    | 14 +--
 .../cxf/systest/jaxrs/tracing/BookStore.java    |  2 +-
 .../htrace/HTraceTracingCustomHeadersTest.java  | 39 ++++----
 .../jaxrs/tracing/htrace/HTraceTracingTest.java | 96 ++++++++++----------
 .../cxf/systest/jaxws/tracing/BookStore.java    |  6 +-
 .../jaxws/tracing/htrace/HTraceTracingTest.java | 54 +++++------
 26 files changed, 333 insertions(+), 309 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
index 9c33696..9e741a3 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
@@ -28,10 +28,11 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.Trace;
-import org.apache.htrace.impl.AlwaysSampler;
-import org.apache.htrace.impl.StandardOutSpanReceiver;
+import org.apache.htrace.core.AlwaysSampler;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.Tracer;
+
+import demo.jaxrs.tracing.conf.TracingConfiguration;
 
 public final class Client {
     private Client() {
@@ -39,10 +40,15 @@ public final class Client {
     
     public static void main(final String[] args) throws Exception {
         final Map<String, String> properties = new HashMap<String, String>();
-        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
-        Trace.addReceiver(new StandardOutSpanReceiver(conf));
+        properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, TracingConfiguration.SPAN_RECEIVER.getName());
+        properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
+        
+        final Tracer tracer = new Tracer.Builder()
+            .name("catalog-client")
+            .conf(HTraceConfiguration.fromMap(properties))
+            .build();
         
-        final HTraceClientProvider provider = new HTraceClientProvider(new AlwaysSampler(conf));
+        final HTraceClientProvider provider = new HTraceClientProvider(tracer);
         final Response response = WebClient
             .create("http://localhost:9000/catalog", Arrays.asList(provider))
             .accept(MediaType.APPLICATION_JSON)

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/conf/TracingConfiguration.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/conf/TracingConfiguration.java b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/conf/TracingConfiguration.java
index 822c3a5..23a2fd3 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/conf/TracingConfiguration.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/conf/TracingConfiguration.java
@@ -19,8 +19,8 @@
 
 package demo.jaxrs.tracing.conf;
 
-import org.apache.htrace.SpanReceiver;
-import org.apache.htrace.impl.StandardOutSpanReceiver;
+import org.apache.htrace.core.SpanReceiver;
+import org.apache.htrace.core.StandardOutSpanReceiver;
 
 public final class TracingConfiguration {
     public static final Class<? extends SpanReceiver> SPAN_RECEIVER = StandardOutSpanReceiver.class;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogApplication.java b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogApplication.java
index 0b15241..1445dc8 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogApplication.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogApplication.java
@@ -31,8 +31,9 @@ import javax.ws.rs.core.Application;
 
 import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.impl.AlwaysSampler;
+import org.apache.htrace.core.AlwaysSampler;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.Tracer;
 
 import demo.jaxrs.tracing.conf.TracingConfiguration;
 
@@ -44,7 +45,7 @@ public class CatalogApplication extends Application {
             return new HashSet<Object>(
                 Arrays.asList(
                     new Catalog(),
-                    new HTraceFeature(HTraceConfiguration.fromMap(getTracingProperties())),
+                    new HTraceFeature(HTraceConfiguration.fromMap(getTracingProperties()), "catalog-server"),
                     new JsrJsonpProvider()
                 )
             );
@@ -55,8 +56,8 @@ public class CatalogApplication extends Application {
     
     private static Map<String, String> getTracingProperties() {
         final Map<String, String> properties = new HashMap<String, String>();
-        properties.put("span.receiver", TracingConfiguration.SPAN_RECEIVER.getName());
-        properties.put("sampler", AlwaysSampler.class.getName());
+        properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, TracingConfiguration.SPAN_RECEIVER.getName());
+        properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
         return properties;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientInterceptor.java
index 4cdbc9c..1358bd8 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientInterceptor.java
@@ -24,15 +24,15 @@ import java.util.Set;
 
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptor;
-import org.apache.htrace.Sampler;
+import org.apache.htrace.core.Tracer;
 
 public abstract class AbstractHTraceClientInterceptor extends AbstractHTraceClientProvider 
         implements PhaseInterceptor<Message> {
     
     private String phase;
 
-    protected AbstractHTraceClientInterceptor(final String phase, final Sampler< ? > sampler) {
-        super(sampler);
+    protected AbstractHTraceClientInterceptor(final String phase, final Tracer tracer) {
+        super(tracer);
         this.phase = phase;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientProvider.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientProvider.java
index d1cbcb0..65aca86 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceClientProvider.java
@@ -26,59 +26,64 @@ import java.util.logging.Logger;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.tracing.AbstractTracingProvider;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.Span;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
+import org.apache.htrace.core.Span;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 public abstract class AbstractHTraceClientProvider extends AbstractTracingProvider { 
     protected static final Logger LOG = LogUtils.getL7dLogger(AbstractHTraceClientProvider.class);
     protected static final String TRACE_SPAN = "org.apache.cxf.tracing.htrace.span";
         
-    private final Sampler< ? > sampler;
+    private final Tracer tracer;
         
-    public AbstractHTraceClientProvider(final Sampler< ? > sampler) {
-        this.sampler = sampler;
+    public AbstractHTraceClientProvider(final Tracer tracer) {
+        this.tracer = tracer;
     }
 
-    protected TraceScope startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
-        Span span = Trace.currentSpan();
-        TraceScope scope = null;
+    protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, 
+            String path, String method) {
+
+        Span span = Tracer.getCurrentSpan();
+        TraceScope traceScope = null;
         
         if (span == null) {
-            scope = Trace.startSpan(buildSpanDescription(path, method), sampler);
-            span = scope.getSpan();
+            traceScope = tracer.newScope(buildSpanDescription(path, method));
+            span = traceScope.getSpan();
         }
         
         if (span != null) {
-            final String traceIdHeader = getTraceIdHeader();
             final String spanIdHeader = getSpanIdHeader();
-            
             // Transfer tracing headers into the response headers
-            requestHeaders.put(traceIdHeader, Collections.singletonList(Long.toString(span.getTraceId())));
-            requestHeaders.put(spanIdHeader, Collections.singletonList(Long.toString(span.getSpanId())));
+            requestHeaders.put(spanIdHeader, Collections.singletonList(span.getSpanId().toString()));
         }
         
         // In case of asynchronous client invocation, the span should be detached as JAX-RS 
         // client request / response filters are going to be executed in different threads.
-        if (isAsyncInvocation() && scope != null) {
-            scope.detach();
+        boolean detached = false;
+        if (isAsyncInvocation() && traceScope != null) {
+            traceScope.detach();
+            detached = true;
         }
         
-        return scope;
+        return new TraceScopeHolder<TraceScope>(traceScope, detached);
     }
     
     private boolean isAsyncInvocation() {
         return !JAXRSUtils.getCurrentMessage().getExchange().isSynchronous();
     }
 
-    protected void stopTraceSpan(final TraceScope scope) {
+    protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder) {
+        if (holder == null) {
+            return;
+        }
+        
+        final TraceScope scope = holder.getScope();
         if (scope != null) {
             // If the client invocation was asynchronous , the trace scope has been created 
             // in another thread and should be re-attached to the current one.
-            if (scope.isDetached()) {
-                final TraceScope continueSpan = Trace.continueSpan(scope.getSpan()); 
-                continueSpan.close();
+            if (holder.isDetached()) {
+                scope.reattach(); 
+                scope.close();
             } else {
                 scope.close();
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
index 7465585..04f907e 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceInterceptor.java
@@ -24,12 +24,12 @@ import java.util.Set;
 
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptor;
-import org.apache.htrace.Sampler;
+import org.apache.htrace.core.Tracer;
 
 public abstract class AbstractHTraceInterceptor extends AbstractHTraceProvider implements PhaseInterceptor<Message> {
     private String phase;
-    protected AbstractHTraceInterceptor(final String phase, final Sampler< ? > sampler) {
-        super(sampler);
+    protected AbstractHTraceInterceptor(final String phase, final Tracer tracer) {
+        super(tracer);
         this.phase = phase;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
index 15e459c..76ca4f3 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/AbstractHTraceProvider.java
@@ -27,94 +27,87 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.tracing.AbstractTracingProvider;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.Span;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceInfo;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.Tracer;
-import org.apache.htrace.impl.MilliSpan;
+import org.apache.htrace.core.SpanId;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 public abstract class AbstractHTraceProvider extends AbstractTracingProvider { 
     protected static final Logger LOG = LogUtils.getL7dLogger(AbstractHTraceProvider.class);
     protected static final String TRACE_SPAN = "org.apache.cxf.tracing.htrace.span";
         
-    private final Sampler< ? > sampler;
+    private final Tracer tracer;
         
-    public AbstractHTraceProvider(final Sampler< ? > sampler) {
-        this.sampler = sampler;
+    public AbstractHTraceProvider(final Tracer tracer) {
+        this.tracer = tracer;
     }
 
-    @SuppressWarnings("unchecked")
-    protected TraceScope startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
-        
-        // Try to extract the Trace Id value from the request header
-        final long traceId = getFirstValueOrDefault(requestHeaders, getTraceIdHeader(), 
-            Tracer.DONT_TRACE.traceId);
+    protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, 
+            String path, String method) {
         
         // Try to extract the Span Id value from the request header
-        final long spanId = getFirstValueOrDefault(requestHeaders, getSpanIdHeader(), 
-            Tracer.DONT_TRACE.spanId); 
+        final SpanId spanId = getFirstValueOrDefault(requestHeaders, getSpanIdHeader(), SpanId.INVALID); 
         
         TraceScope traceScope = null;
-        if (traceId == Tracer.DONT_TRACE.traceId || spanId == Tracer.DONT_TRACE.spanId) {
-            traceScope = Trace.startSpan(buildSpanDescription(path, method), (Sampler< TraceInfo >)sampler);
+        if (spanId == SpanId.INVALID) {
+            traceScope = tracer.newScope(buildSpanDescription(path, method));
         } else {
-            traceScope = Trace.startSpan(buildSpanDescription(path, method), new MilliSpan
-                .Builder()
-                .spanId(spanId)
-                .traceId(traceId)
-                .build());
+            traceScope = tracer.newScope(buildSpanDescription(path, method), spanId);
         }
         
         // If the service resource is using asynchronous processing mode, the trace
         // scope will be closed in another thread and as such should be detached.
+        boolean detached = false;
         if (isAsyncResponse()) {
-            propagateContinuationSpan(traceScope.detach());
+            traceScope.detach();
+            propagateContinuationSpan(traceScope);
+            detached = true;
         }
         
-        return traceScope;
+        return new TraceScopeHolder<TraceScope>(traceScope, detached);
     }
 
     protected void stopTraceSpan(final Map<String, List<String>> requestHeaders,
                                  final Map<String, List<Object>> responseHeaders,
-                                 final TraceScope span) {
-        final String traceIdHeader = getTraceIdHeader();
+                                 final TraceScopeHolder<TraceScope> holder) {
         final String spanIdHeader = getSpanIdHeader();
 
         // Transfer tracing headers into the response headers
-        if (requestHeaders.containsKey(traceIdHeader) && requestHeaders.containsKey(spanIdHeader)) {
-            responseHeaders.put(traceIdHeader, CastUtils.cast(requestHeaders.get(traceIdHeader)));
+        if (requestHeaders.containsKey(spanIdHeader)) {
             responseHeaders.put(spanIdHeader, CastUtils.cast(requestHeaders.get(spanIdHeader)));
         }
         
+        if (holder == null) {
+            return;
+        }
+        
+        final TraceScope span = holder.getScope();
         if (span != null) {
             // 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 (span.isDetached()) {
-                final TraceScope continueSpan = Trace.continueSpan(span.getSpan()); 
-                continueSpan.close();
+            if (holder.isDetached()) {
+                span.reattach(); 
+                span.close();
             } else {            
                 span.close();
             }
         }
     }
     
-    private void propagateContinuationSpan(final Span continuationSpan) {
-        JAXRSUtils.getCurrentMessage().put(Span.class, continuationSpan);
+    private void propagateContinuationSpan(final TraceScope continuationScope) {
+        JAXRSUtils.getCurrentMessage().put(TraceScope.class, continuationScope);
     }
     
     protected boolean isAsyncResponse() {
         return !JAXRSUtils.getCurrentMessage().getExchange().isSynchronous();
     }
     
-    private static Long getFirstValueOrDefault(final Map<String, List<String>> headers, 
-            final String header, final long defaultValue) {
+    private static SpanId getFirstValueOrDefault(final Map<String, List<String>> headers, 
+            final String header, final SpanId defaultValue) {
         List<String> value = headers.get(header);
         if (value != null && !value.isEmpty()) {
             try {
-                return Long.parseLong(value.get(0));
+                return SpanId.fromString(value.get(0));
             } catch (NumberFormatException ex) {
                 LOG.log(Level.FINE, String.format("Unable to parse '%s' header value to long number", header), ex);
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStartInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStartInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStartInterceptor.java
index feb1512..8af55ff 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStartInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStartInterceptor.java
@@ -25,24 +25,28 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.TraceScope;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 public class HTraceClientStartInterceptor extends AbstractHTraceClientInterceptor {
-    public HTraceClientStartInterceptor(final Sampler< ? > sampler) {
-        this(Phase.PRE_STREAM, sampler);
+    public HTraceClientStartInterceptor(final Tracer tracer) {
+        this(Phase.PRE_STREAM, tracer);
     }
 
-    public HTraceClientStartInterceptor(final String phase, final Sampler< ? > sampler) {
-        super(phase, sampler);
+    public HTraceClientStartInterceptor(final String phase, final Tracer tracer) {
+        super(phase, tracer);
     }
 
     @Override
     public void handleMessage(Message message) throws Fault {
-        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); 
-        TraceScope scope = super.startTraceSpan(headers, (String)message.get(Message.ENDPOINT_ADDRESS), 
+        final Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(headers, 
+            (String)message.get(Message.ENDPOINT_ADDRESS), 
             (String)message.get(Message.HTTP_REQUEST_METHOD));
-        message.getExchange().put(TRACE_SPAN, scope);
+        
+        if (holder != null) {
+            message.getExchange().put(TRACE_SPAN, holder);
+        }
     }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStopInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStopInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStopInterceptor.java
index d52fb07..e58f529 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStopInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceClientStopInterceptor.java
@@ -21,7 +21,7 @@ package org.apache.cxf.tracing.htrace;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
-import org.apache.htrace.TraceScope;
+import org.apache.htrace.core.TraceScope;
 
 public class HTraceClientStopInterceptor extends AbstractHTraceClientInterceptor {
     public HTraceClientStopInterceptor() {
@@ -34,8 +34,9 @@ public class HTraceClientStopInterceptor extends AbstractHTraceClientInterceptor
 
     @Override
     public void handleMessage(Message message) throws Fault {
-        final TraceScope span = (TraceScope)message.getExchange().get(TRACE_SPAN);
-        super.stopTraceSpan(span);
+        @SuppressWarnings("unchecked")
+        final TraceScopeHolder<TraceScope> holder = 
+            (TraceScopeHolder<TraceScope>)message.getExchange().get(TRACE_SPAN);
+        super.stopTraceSpan(holder);
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
index 2cefbc5..5301c4a 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStartInterceptor.java
@@ -24,20 +24,24 @@ import java.util.Map;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Message;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.TraceScope;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 public class HTraceStartInterceptor extends AbstractHTraceInterceptor {
-    public HTraceStartInterceptor(final String phase, final Sampler< ? > sampler) {
-        super(phase, sampler);
+    public HTraceStartInterceptor(final String phase, final Tracer tracer) {
+        super(phase, tracer);
     }
 
     @Override
     public void handleMessage(Message message) throws Fault {
-        Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); 
-        TraceScope scope = super.startTraceSpan(headers, (String)message.get(Message.REQUEST_URI), 
+        final Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(headers, 
+            (String)message.get(Message.REQUEST_URI), 
             (String)message.get(Message.HTTP_REQUEST_METHOD));
-        message.getExchange().put(TRACE_SPAN, scope);
+        
+        if (holder != null) {
+            message.getExchange().put(TRACE_SPAN, holder);
+        }
     }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
index 2bb1da6..75be08b 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceStopInterceptor.java
@@ -26,7 +26,7 @@ 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.htrace.TraceScope;
+import org.apache.htrace.core.TraceScope;
 
 public class HTraceStopInterceptor extends AbstractHTraceInterceptor {
     public HTraceStopInterceptor(final String phase) {
@@ -48,9 +48,11 @@ public class HTraceStopInterceptor extends AbstractHTraceInterceptor {
         Map<String, List<String>> requestHeaders =  
             CastUtils.cast((Map<?, ?>)requestMessage.get(Message.PROTOCOL_HEADERS));
         
-        TraceScope span = (TraceScope)message.getExchange().get(TRACE_SPAN);
+        @SuppressWarnings("unchecked")
+        final TraceScopeHolder<TraceScope> holder = 
+            (TraceScopeHolder<TraceScope>)message.getExchange().get(TRACE_SPAN);
         
-        super.stopTraceSpan(requestHeaders, responseHeaders, span);
+        super.stopTraceSpan(requestHeaders, responseHeaders, holder);
     }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceTracerContext.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceTracerContext.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceTracerContext.java
index 3194154..cc8b2c9 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceTracerContext.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/HTraceTracerContext.java
@@ -18,79 +18,75 @@
  */
 package org.apache.cxf.tracing.htrace;
 
-import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Callable;
 
 import org.apache.cxf.tracing.Traceable;
 import org.apache.cxf.tracing.TracerContext;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.Span;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.wrappers.TraceCallable;
+import org.apache.htrace.core.Span;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 public class HTraceTracerContext implements TracerContext {
-    private final Sampler< ? > sampler;
-    private final Span continuationSpan;
+    private final Tracer tracer;
+    private final TraceScope continuationScope;
 
-    public HTraceTracerContext(final Sampler< ? > sampler) {
-        this(sampler, null);
+    public HTraceTracerContext(final Tracer tracer) {
+        this(tracer, null);
     }
 
-    public HTraceTracerContext(final Sampler< ? > sampler, final Span continuationSpan) {
-        this.sampler = sampler;
-        this.continuationSpan = continuationSpan;
+    public HTraceTracerContext(final Tracer tracer, final TraceScope continuationScope) {
+        this.tracer = tracer;
+        this.continuationScope = continuationScope;
     }
         
     @Override
     @SuppressWarnings("unchecked")
     public TraceScope startSpan(final String description) {
-        return Trace.startSpan(description, sampler);
+        return tracer.newScope(description);
     }
     
     @Override
     public <T> T continueSpan(final Traceable<T> traceable) throws Exception {
-        TraceScope continueSpan = null;
-        
-        if (!Trace.isTracing() && continuationSpan != null) {
-            continueSpan = Trace.continueSpan(continuationSpan);
+        if (!isTracing() && continuationScope != null) {
+            continuationScope.reattach();
         }
         
         try {
-            return traceable.call(new HTraceTracerContext(sampler));
+            return traceable.call(new HTraceTracerContext(tracer));
         } finally {
-            if (continueSpan != null) {
-                continueSpan.close();
-            }
+            continuationScope.detach();
         }
     }
     
     @Override
-    public <T> Callable<T> wrap(final String desription, final Traceable<T> traceable) {
+    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 HTraceTracerContext(sampler));
+                return traceable.call(new HTraceTracerContext(tracer));
             }
         };
         
-        // TODO: Replace with HTrace's wrap() method once the version with
-        // callable and description becomes available.
-        if (Trace.isTracing()) {
-            return new TraceCallable<T>(Trace.currentSpan(), callable, desription);
-        } else {
-            return callable;
-        }
+        return tracer.wrap(callable, description);
     }
     
     @Override
     public void annotate(String key, String value) {
-        Trace.addKVAnnotation(key.getBytes(StandardCharsets.UTF_8), 
-            value.getBytes(StandardCharsets.UTF_8));
+        final Span currentSpan = Tracer.getCurrentSpan();
+        if (currentSpan != null) {
+            currentSpan.addKVAnnotation(key, value);
+        }
     }
     
     @Override
     public void timeline(String message) {
-        Trace.addTimelineAnnotation(message);
+        final Span currentSpan = Tracer.getCurrentSpan();
+        if (currentSpan != null) {
+            currentSpan.addTimelineAnnotation(message);
+        }
+    }
+    
+    private boolean isTracing() {
+        return Tracer.getCurrentSpan() != null;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
index 7a5f2c1..0e4b5b8 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceClientProvider.java
@@ -27,37 +27,34 @@ import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.tracing.htrace.AbstractHTraceClientProvider;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.impl.NeverSampler;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 @Provider
 public class HTraceClientProvider extends AbstractHTraceClientProvider 
         implements ClientRequestFilter, ClientResponseFilter {
     private static final String TRACE_SPAN = "org.apache.cxf.tracing.client.htrace.span";
     
-    public HTraceClientProvider() {
-        this(NeverSampler.INSTANCE);
-    }
-
-    public HTraceClientProvider(final Sampler< ? > sampler) {
-        super(sampler);
+    public HTraceClientProvider(final Tracer tracer) {
+        super(tracer);
     }
 
     @Override
     public void filter(final ClientRequestContext requestContext) throws IOException {
-        final TraceScope scope = super.startTraceSpan(requestContext.getStringHeaders(), 
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getStringHeaders(), 
             requestContext.getUri().toString(), requestContext.getMethod());
 
-        if (scope != null) {
-            requestContext.setProperty(TRACE_SPAN, scope);
+        if (holder != null) {
+            requestContext.setProperty(TRACE_SPAN, holder);
         }
     }
     
+    @SuppressWarnings("unchecked")
     @Override
     public void filter(final ClientRequestContext requestContext,
             final ClientResponseContext responseContext) throws IOException {
-        final TraceScope scope = (TraceScope)requestContext.getProperty(TRACE_SPAN);
-        super.stopTraceSpan(scope);
+        final TraceScopeHolder<TraceScope> holder = 
+            (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN);
+        super.stopTraceSpan(holder);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceContextProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceContextProvider.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceContextProvider.java
index b2f122e..73be373 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceContextProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceContextProvider.java
@@ -24,29 +24,28 @@ import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.tracing.TracerContext;
 import org.apache.cxf.tracing.htrace.HTraceTracerContext;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.Span;
-import org.apache.htrace.impl.NeverSampler;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 @Provider
 public class HTraceContextProvider implements ContextProvider< TracerContext > {
-    private Sampler< ? > sampler = NeverSampler.INSTANCE;
+    private final Tracer tracer;
     
-    public HTraceContextProvider(final Sampler< ? > sampler) {
-        this.sampler = sampler;
+    public HTraceContextProvider(final Tracer tracer) {
+        this.tracer = tracer;
     }
 
     @Override
     public TracerContext createContext(final Message message) {
         // Check if there is a trace scope passed along with the message
-        final Span continuationSpan = message.get(Span.class);
+        final TraceScope continuationScope = message.get(TraceScope.class);
         
         // If trace scope is already present, let us check if it is detached 
         // (asynchronous invocation)
-        if (continuationSpan != null) {
-            return new HTraceTracerContext(sampler, continuationSpan);
+        if (continuationScope != null) {
+            return new HTraceTracerContext(tracer, continuationScope);
         }
         
-        return new HTraceTracerContext(sampler);
+        return new HTraceTracerContext(tracer);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceFeature.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceFeature.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceFeature.java
index 6409846..2658fa3 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceFeature.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceFeature.java
@@ -24,22 +24,20 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.SamplerBuilder;
-import org.apache.htrace.SpanReceiver;
-import org.apache.htrace.SpanReceiverBuilder;
-import org.apache.htrace.Trace;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.Tracer;
 
 public class HTraceFeature extends AbstractFeature {
     private HTraceConfiguration configuration;
+    private String name;
     
     public HTraceFeature() {
-        this(HTraceConfiguration.EMPTY);
+        this(HTraceConfiguration.EMPTY, "");
     }
 
-    public HTraceFeature(final HTraceConfiguration configuration) {
+    public HTraceFeature(final HTraceConfiguration configuration, final String name) {
         this.configuration = configuration;
+        this.name = name;
     }
 
     @Override
@@ -48,16 +46,14 @@ public class HTraceFeature extends AbstractFeature {
             .getEndpoint()
             .get(ServerProviderFactory.class.getName());
 
-        final Sampler< ? > sampler = new SamplerBuilder(configuration).build();
-        final SpanReceiver spanReceiver = new SpanReceiverBuilder(configuration).build();
+        final Tracer tracer = new Tracer.Builder()
+            .conf(configuration)
+            .name(name)
+            .build();
         
-        if (spanReceiver != null) {
-            Trace.addReceiver(spanReceiver);
-        }
-
         if (providerFactory != null) {
-            providerFactory.setUserProviders(Arrays.asList(new HTraceProvider(sampler), 
-                new HTraceContextProvider(sampler)));
+            providerFactory.setUserProviders(Arrays.asList(new HTraceProvider(tracer), 
+                new HTraceContextProvider(tracer)));
         }
     }
     
@@ -68,4 +64,12 @@ public class HTraceFeature extends AbstractFeature {
     public HTraceConfiguration getConfiguration() {
         return configuration;
     }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public String getName() {
+        return name;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceProvider.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceProvider.java b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceProvider.java
index d420c56..47c4d74 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceProvider.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/jaxrs/HTraceProvider.java
@@ -31,40 +31,37 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.tracing.htrace.AbstractHTraceProvider;
-import org.apache.htrace.Sampler;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.impl.NeverSampler;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 @Provider
 public class HTraceProvider extends AbstractHTraceProvider 
     implements ContainerRequestFilter, ContainerResponseFilter {
     @Context 
     private ResourceInfo resourceInfo;
-    public HTraceProvider() {
-        this(NeverSampler.INSTANCE);
-    }
-
-    public HTraceProvider(final Sampler< ? > sampler) {
-        super(sampler);
+    
+    public HTraceProvider(final Tracer tracer) {
+        super(tracer);
     }
 
     @Override
     public void filter(final ContainerRequestContext requestContext) throws IOException {
-        TraceScope scope = super.startTraceSpan(requestContext.getHeaders(), 
+        final TraceScopeHolder<TraceScope> holder = super.startTraceSpan(requestContext.getHeaders(), 
                                                 requestContext.getUriInfo().getPath(),
                                                 requestContext.getMethod());
         
-        if (scope != null) {
-            requestContext.setProperty(TRACE_SPAN, scope);
+        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(), 
-                            (TraceScope)requestContext.getProperty(TRACE_SPAN));
+                            (TraceScopeHolder<TraceScope>)requestContext.getProperty(TRACE_SPAN));
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 14a31e3..f563ca3 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -191,7 +191,7 @@
         <cxf.olingo.version>1.2.0</cxf.olingo.version>
         <cxf.tika.version>1.6</cxf.tika.version>
         <cxf.jexl.version>2.1.1</cxf.jexl.version>
-        <cxf.htrace.version>3.2.0-incubating</cxf.htrace.version>
+        <cxf.htrace.version>4.0.0-incubating</cxf.htrace.version>
         <cxf.checkstyle.extension />
         <cxf.jaxb.context.class />
         <cxf.jaxb.context.class.property>none</cxf.jaxb.context.class.property>

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java b/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
index 5c696d8..6c45864 100644
--- a/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
+++ b/rt/management/src/main/java/org/apache/cxf/tracing/AbstractTracingProvider.java
@@ -18,22 +18,39 @@
  */
 package org.apache.cxf.tracing;
 
+import java.io.Serializable;
+
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
 import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_SPAN_ID;
-import static org.apache.cxf.tracing.TracerHeaders.DEFAULT_HEADER_TRACE_ID;
 
 public abstract class AbstractTracingProvider {
     protected static String getSpanIdHeader() {
         return getHeaderOrDefault(TracerHeaders.HEADER_SPAN_ID, DEFAULT_HEADER_SPAN_ID);
     }
     
-    protected static String getTraceIdHeader() {
-        return getHeaderOrDefault(TracerHeaders.HEADER_TRACE_ID, DEFAULT_HEADER_TRACE_ID);
-    }
+    protected static class TraceScopeHolder<T> implements Serializable {
+        private static final long serialVersionUID = -5985783659818936359L;
 
+        private final T scope;
+        private final boolean detached;
+        
+        public TraceScopeHolder(final T scope, final boolean detached) {
+            this.scope = scope;
+            this.detached = detached;
+        }
+        
+        public T getScope() {
+            return scope;
+        }
+        
+        public boolean isDetached() {
+            return detached;
+        }
+    }
+    
     private static String getHeaderOrDefault(final String property, final String fallback) {
         final Message message = PhaseInterceptorChain.getCurrentMessage();
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/rt/management/src/main/java/org/apache/cxf/tracing/TracerContext.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/tracing/TracerContext.java b/rt/management/src/main/java/org/apache/cxf/tracing/TracerContext.java
index a13923e..9e41de3 100644
--- a/rt/management/src/main/java/org/apache/cxf/tracing/TracerContext.java
+++ b/rt/management/src/main/java/org/apache/cxf/tracing/TracerContext.java
@@ -33,18 +33,18 @@ public interface TracerContext {
     
     /**
      * Starts a new span in the current thread.
-     * @param desription span description
+     * @param description span description
      * @return span instance object
      */
-    <T> T startSpan(final String desription);
+    <T> T startSpan(final String description);
     
     /**
      * Wraps the traceable into a new span, preserving the current span as a parent.
-     * @param desription span description
+     * @param description span description
      * @param traceable  traceable implementation to be wrapped
      * @return callable to be executed (in current thread or any other thread pool)
      */
-    <T> Callable<T> wrap(final String desription, final Traceable<T> traceable);
+    <T> Callable<T> wrap(final String description, final Traceable<T> traceable);
     
     
     /**

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/rt/management/src/main/java/org/apache/cxf/tracing/TracerHeaders.java
----------------------------------------------------------------------
diff --git a/rt/management/src/main/java/org/apache/cxf/tracing/TracerHeaders.java b/rt/management/src/main/java/org/apache/cxf/tracing/TracerHeaders.java
index dd212ca..653f958 100644
--- a/rt/management/src/main/java/org/apache/cxf/tracing/TracerHeaders.java
+++ b/rt/management/src/main/java/org/apache/cxf/tracing/TracerHeaders.java
@@ -19,10 +19,7 @@
 package org.apache.cxf.tracing;
 
 public final class TracerHeaders {
-    public static final String HEADER_TRACE_ID = "org.apache.cxf.tracing.header.trace_id";
     public static final String HEADER_SPAN_ID = "org.apache.cxf.tracing.header.span_id";
-    
-    public static final String DEFAULT_HEADER_TRACE_ID = "X-Trace-Id";
     public static final String DEFAULT_HEADER_SPAN_ID = "X-Span-Id";
     
     private TracerHeaders() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReceiver.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReceiver.java b/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReceiver.java
index e5f6c97..0e896c5 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReceiver.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/TestSpanReceiver.java
@@ -23,23 +23,17 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.Span;
-import org.apache.htrace.SpanReceiver;
-import org.apache.htrace.Trace;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.Span;
+import org.apache.htrace.core.SpanReceiver;
 
 /**
  * Test HTrace Span receiver
  */
-public class TestSpanReceiver implements SpanReceiver {
+public class TestSpanReceiver extends SpanReceiver {
     private static List<Span> spans = new ArrayList<Span>();
-    private static TestSpanReceiver instance;
 
     public TestSpanReceiver(final HTraceConfiguration conf) {
-        if (instance != null) {
-            Trace.removeReceiver(instance);
-        }
-        instance = this;
     }
 
     public Collection<Span> getSpans() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/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 a177852..7df41da 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
@@ -39,7 +39,7 @@ 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.TraceScope;
+import org.apache.htrace.core.TraceScope;
 
 @Path("/bookstore/")
 public class BookStore {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
index 0371c9e..ccc6b85 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingCustomHeadersTest.java
@@ -39,9 +39,11 @@ import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 import org.apache.cxf.tracing.TracerHeaders;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.impl.AlwaysSampler;
-import org.apache.htrace.impl.StandardOutSpanReceiver;
+import org.apache.htrace.core.AlwaysSampler;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.SpanId;
+import org.apache.htrace.core.StandardOutSpanReceiver;
+import org.apache.htrace.core.Tracer;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -54,27 +56,26 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
     public static final String PORT = allocatePort(HTraceTracingCustomHeadersTest.class);
     
     private static final String CUSTOM_HEADER_SPAN_ID = "My-Span-Id";
-    private static final String CUSTOM_HEADER_TRACE_ID = "My-Trace-Id";
     
+    private Tracer tracer;
     private HTraceClientProvider htraceClientProvider;
     
     @Ignore
     public static class Server extends AbstractBusTestServerBase {
         protected void run() {
             final Map<String, String> properties = new HashMap<String, String>();
-            properties.put("span.receiver", StandardOutSpanReceiver.class.getName());
-            properties.put("sampler", AlwaysSampler.class.getName());
+            properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, StandardOutSpanReceiver.class.getName());
+            properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
             
             final Map<String, Object> headers = new HashMap<String, Object>();
             headers.put(TracerHeaders.HEADER_SPAN_ID, CUSTOM_HEADER_SPAN_ID);
-            headers.put(TracerHeaders.HEADER_TRACE_ID, CUSTOM_HEADER_TRACE_ID);
             
             final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
             sf.setResourceClasses(BookStore.class);
             sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore()));
             sf.setAddress("http://localhost:" + PORT);
             sf.setProvider(new JacksonJsonProvider());
-            sf.setFeatures(Arrays.asList(new HTraceFeature(HTraceConfiguration.fromMap(properties))));
+            sf.setFeatures(Arrays.asList(new HTraceFeature(HTraceConfiguration.fromMap(properties), "test-tracer")));
             sf.setProperties(headers);
             sf.create();
         }
@@ -90,20 +91,28 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
     
     @Before
     public void setUp() {
-        htraceClientProvider = new HTraceClientProvider(
-            new AlwaysSampler(HTraceConfiguration.EMPTY));
+        final Map<String, String> properties = new HashMap<String, String>();
+        properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, StandardOutSpanReceiver.class.getName());
+        properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
+        
+        tracer = new Tracer.Builder()
+            .name("tracer")
+            .conf(HTraceConfiguration.fromMap(properties))
+            .build();
+
+        htraceClientProvider = new HTraceClientProvider(tracer);
     }
     
     @Test
     public void testThatNewSpanIsCreated() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/books")
-            .header(CUSTOM_HEADER_TRACE_ID, 10L)
-            .header(CUSTOM_HEADER_SPAN_ID, 20L)
+            .header(CUSTOM_HEADER_SPAN_ID, spanId.toString())
             .get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
-        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
@@ -111,7 +120,6 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
         final Response r = createWebClient("/bookstore/books", htraceClientProvider).get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
-        assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_TRACE_ID), notNullValue());
         assertThat((String)r.getHeaders().getFirst(CUSTOM_HEADER_SPAN_ID), notNullValue());
     }
 
@@ -123,7 +131,6 @@ public class HTraceTracingCustomHeadersTest extends AbstractBusClientServerTestB
         if (providers.length > 0) {
             final ClientConfiguration config = WebClient.getConfig(client);
             config.getRequestContext().put(TracerHeaders.HEADER_SPAN_ID, CUSTOM_HEADER_SPAN_ID);
-            config.getRequestContext().put(TracerHeaders.HEADER_TRACE_ID, CUSTOM_HEADER_TRACE_ID);
         }
 
         return client;

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
index 74704ba..9c88ffa 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/htrace/HTraceTracingTest.java
@@ -42,10 +42,12 @@ import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 import org.apache.cxf.tracing.TracerHeaders;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceClientProvider;
 import org.apache.cxf.tracing.htrace.jaxrs.HTraceFeature;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.impl.AlwaysSampler;
+import org.apache.htrace.core.AlwaysSampler;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.SpanId;
+import org.apache.htrace.core.StandardOutSpanReceiver;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -56,21 +58,22 @@ import static org.hamcrest.CoreMatchers.equalTo;
 public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     public static final String PORT = allocatePort(HTraceTracingTest.class);
     
+    private Tracer tracer;
     private HTraceClientProvider htraceClientProvider;
 
     @Ignore
     public static class Server extends AbstractBusTestServerBase {
         protected void run() {
             final Map<String, String> properties = new HashMap<String, String>();
-            properties.put("span.receiver", TestSpanReceiver.class.getName());
-            properties.put("sampler", AlwaysSampler.class.getName());
+            properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, TestSpanReceiver.class.getName());
+            properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
             
             final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
             sf.setResourceClasses(BookStore.class);
             sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore()));
             sf.setAddress("http://localhost:" + PORT);
             sf.setProvider(new JacksonJsonProvider());
-            sf.setFeatures(Arrays.asList(new HTraceFeature(HTraceConfiguration.fromMap(properties))));
+            sf.setFeatures(Arrays.asList(new HTraceFeature(HTraceConfiguration.fromMap(properties), "tracer")));
             sf.create();
         }
     }
@@ -87,8 +90,16 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     public void setUp() {
         TestSpanReceiver.clear();
         
-        htraceClientProvider = new HTraceClientProvider(
-            new AlwaysSampler(HTraceConfiguration.EMPTY));
+        final Map<String, String> properties = new HashMap<String, String>();
+        properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, StandardOutSpanReceiver.class.getName());
+        properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
+        
+        tracer = new Tracer.Builder()
+            .name("tracer")
+            .conf(HTraceConfiguration.fromMap(properties))
+            .build();
+        
+        htraceClientProvider = new HTraceClientProvider(tracer);
     }
     
     @Test
@@ -100,15 +111,15 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books"));
         
-        assertFalse(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_TRACE_ID));
         assertFalse(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
     }
     
     @Test
     public void testThatNewInnerSpanIsCreated() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/books")
-            .header(TracerHeaders.DEFAULT_HEADER_TRACE_ID, 10L)
-            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, 20L)
+            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, spanId.toString())
             .get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
@@ -116,15 +127,15 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books"));
         
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
     public void testThatCurrentSpanIsAnnotatedWithKeyValue() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/book/1")
-            .header(TracerHeaders.DEFAULT_HEADER_TRACE_ID, 10L)
-            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, 20L)
+            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, spanId.toString())
             .get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
@@ -132,15 +143,15 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("GET bookstore/book/1"));
         assertThat(TestSpanReceiver.getAllSpans().get(0).getKVAnnotations().size(), equalTo(1));
         
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
     public void testThatParallelSpanIsAnnotatedWithTimeline() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/process")
-            .header(TracerHeaders.DEFAULT_HEADER_TRACE_ID, 10L)
-            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, 20L)
+            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, spanId.toString())
             .put("");
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
@@ -150,8 +161,7 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("Processing books"));
         assertThat(TestSpanReceiver.getAllSpans().get(1).getTimelineAnnotations().size(), equalTo(1));
         
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
@@ -163,31 +173,31 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
         assertThat(TestSpanReceiver.getAllSpans().get(0).getParents().length, equalTo(1));
         
-        assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_TRACE_ID));
         assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
     }
     
     @Test
     public void testThatNewInnerSpanIsCreatedUsingAsyncInvocation() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/books/async")
-            .header(TracerHeaders.DEFAULT_HEADER_TRACE_ID, 10L)
-            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, 20L)
+            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, spanId.toString())
             .get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
         assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
-        assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("GET bookstore/books/async"));
-        assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("Processing books"));
+        assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books/async"));
+        assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Processing books"));
         
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
     public void testThatOuterSpanIsCreatedUsingAsyncInvocation() {
+        final SpanId spanId = SpanId.fromRandom();
+        
         final Response r = createWebClient("/bookstore/books/async/notrace")
-            .header(TracerHeaders.DEFAULT_HEADER_TRACE_ID, 10L)
-            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, 20L)
+            .header(TracerHeaders.DEFAULT_HEADER_SPAN_ID, spanId.toString())
             .get();
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
@@ -195,8 +205,7 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), 
             equalTo("GET bookstore/books/async/notrace"));
         
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_TRACE_ID), equalTo("10"));
-        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo("20"));
+        assertThat((String)r.getHeaders().getFirst(TracerHeaders.DEFAULT_HEADER_SPAN_ID), equalTo(spanId.toString()));
     }
     
     @Test
@@ -205,8 +214,8 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertEquals(Status.OK.getStatusCode(), r.getStatus());
         
         assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
-        assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("GET bookstore/books/async"));
-        assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("Processing books"));
+        assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books/async"));
+        assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Processing books"));
     }
     
     @Test
@@ -222,17 +231,12 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books"));
         assertThat(TestSpanReceiver.getAllSpans().get(2).getDescription(), equalTo("GET " + client.getCurrentURI()));
         
-        assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_TRACE_ID));
         assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
     }
     
     @Test
     public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
-        final Map<String, String> properties = new HashMap<String, String>();
-        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);        
-        final AlwaysSampler sampler = new AlwaysSampler(conf);
-        
-        try (final TraceScope scope = Trace.startSpan("test span", sampler)) {
+        try (final TraceScope scope = tracer.newScope("test span")) {
             final Response r = createWebClient("/bookstore/books", htraceClientProvider).get();
             assertEquals(Status.OK.getStatusCode(), r.getStatus());
             
@@ -241,7 +245,6 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
             assertThat(TestSpanReceiver.getAllSpans().get(0).getParents().length, equalTo(1));
             assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books"));
             
-            assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_TRACE_ID));
             assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
         }
         
@@ -251,23 +254,18 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     
     @Test
     public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
-        final Map<String, String> properties = new HashMap<String, String>();
-        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);        
-        final AlwaysSampler sampler = new AlwaysSampler(conf);
-
         final WebClient client = createWebClient("/bookstore/books", htraceClientProvider);
-        try (final TraceScope scope = Trace.startSpan("test span", sampler)) {
+        try (final TraceScope scope = tracer.newScope("test span")) {
             final Future<Response> f = client.async().get();
         
             final Response r = f.get(1, TimeUnit.SECONDS);
             assertEquals(Status.OK.getStatusCode(), r.getStatus());
-            assertThat(scope.isDetached(), equalTo(false));
+            assertThat(Tracer.getCurrentSpan(), equalTo(scope.getSpan()));
             
             assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
             assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
             assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("GET bookstore/books"));
             
-            assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_TRACE_ID));
             assertTrue(r.getHeaders().containsKey(TracerHeaders.DEFAULT_HEADER_SPAN_ID));
         }
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/BookStore.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/BookStore.java
index 35baec7..b9ee6ae 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/BookStore.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/BookStore.java
@@ -26,14 +26,14 @@ import javax.jws.WebMethod;
 import javax.jws.WebService;
 
 import org.apache.cxf.systest.Book;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 
 @WebService(endpointInterface = "org.apache.cxf.systest.jaxws.tracing.BookStoreService", serviceName = "BookStore")
 public class BookStore implements BookStoreService {
     @WebMethod
     public Collection< Book > getBooks() {
-        try (final TraceScope span =  Trace.startSpan("Get Books")) {
+        try (final TraceScope span = Tracer.curThreadTracer().newScope("Get Books")) {
             return Arrays.asList(
                 new Book("Apache CXF in Action", UUID.randomUUID().toString()),
                 new Book("Mastering Apache CXF", UUID.randomUUID().toString())

http://git-wip-us.apache.org/repos/asf/cxf/blob/c5c21d5b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
----------------------------------------------------------------------
diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
index 1bee153..8fb1cc2 100644
--- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
+++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/htrace/HTraceTracingTest.java
@@ -43,10 +43,11 @@ import org.apache.cxf.tracing.htrace.HTraceClientStartInterceptor;
 import org.apache.cxf.tracing.htrace.HTraceClientStopInterceptor;
 import org.apache.cxf.tracing.htrace.HTraceStartInterceptor;
 import org.apache.cxf.tracing.htrace.HTraceStopInterceptor;
-import org.apache.htrace.HTraceConfiguration;
-import org.apache.htrace.Trace;
-import org.apache.htrace.TraceScope;
-import org.apache.htrace.impl.AlwaysSampler;
+import org.apache.htrace.core.AlwaysSampler;
+import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.SpanId;
+import org.apache.htrace.core.TraceScope;
+import org.apache.htrace.core.Tracer;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -63,14 +64,11 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     @Ignore
     public static class Server extends AbstractBusTestServerBase {
         protected void run() {
-            final Map<String, String> properties = new HashMap<String, String>();
-            final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
-            Trace.addReceiver(new TestSpanReceiver(conf));
-            
+            final Tracer tracer = createTracer();
             final JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
             sf.setServiceClass(BookStore.class);
             sf.setAddress("http://localhost:" + PORT);
-            sf.getInInterceptors().add(new HTraceStartInterceptor(Phase.PRE_INVOKE, new AlwaysSampler(conf)));
+            sf.getInInterceptors().add(new HTraceStartInterceptor(Phase.PRE_INVOKE, tracer));
             sf.getOutInterceptors().add(new HTraceStopInterceptor(Phase.PRE_MARSHAL));
             sf.create();
         }
@@ -102,15 +100,14 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("POST /BookStore"));
         
         final Map<String, List<String>> response = getResponseHeaders(service);
-        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), nullValue());
         assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), nullValue());
     }
     
     @Test
     public void testThatNewInnerSpanIsCreated() throws MalformedURLException {
+        final SpanId spanId = SpanId.fromRandom();
         final Map<String, List<String>> headers = new HashMap<String, List<String>>();
-        headers.put(TracerHeaders.DEFAULT_HEADER_TRACE_ID, Arrays.asList("10"));
-        headers.put(TracerHeaders.DEFAULT_HEADER_SPAN_ID, Arrays.asList("20"));
+        headers.put(TracerHeaders.DEFAULT_HEADER_SPAN_ID, Arrays.asList(spanId.toString()));
 
         final BookStoreService service = createJaxWsService(headers);
         assertThat(service.getBooks().size(), equalTo(2));
@@ -120,19 +117,17 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(1).getDescription(), equalTo("POST /BookStore"));
         
         final Map<String, List<String>> response = getResponseHeaders(service);
-        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), hasItems("10"));
-        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), hasItems("20"));
+        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), hasItems(spanId.toString()));
     }
     
     @Test
     public void testThatNewChildSpanIsCreatedWhenParentIsProvided() throws MalformedURLException {
-        final Map<String, String> properties = new HashMap<String, String>();
-        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
+        final Tracer tracer = createTracer();
     
         final BookStoreService service = createJaxWsService(new Configurator() {
             @Override
             public void configure(final JaxWsProxyFactoryBean factory) {
-                factory.getOutInterceptors().add(new HTraceClientStartInterceptor(new AlwaysSampler(conf)));
+                factory.getOutInterceptors().add(new HTraceClientStartInterceptor(tracer));
                 factory.getInInterceptors().add(new HTraceClientStopInterceptor());
             }
         });
@@ -146,27 +141,24 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
             equalTo("POST http://localhost:" + PORT + "/BookStore"));
         
         final Map<String, List<String>> response = getResponseHeaders(service);
-        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), not(nullValue()));
         assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), not(nullValue()));
     }
     
     @Test
     public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
-        final Map<String, String> properties = new HashMap<String, String>();
-        final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
+        final Tracer tracer = createTracer();
     
-        final AlwaysSampler sampler = new AlwaysSampler(conf);
         final BookStoreService service = createJaxWsService(new Configurator() {
             @Override
             public void configure(final JaxWsProxyFactoryBean factory) {
-                factory.getOutInterceptors().add(new HTraceClientStartInterceptor(sampler));
+                factory.getOutInterceptors().add(new HTraceClientStartInterceptor(tracer));
                 factory.getInInterceptors().add(new HTraceClientStopInterceptor());
             }
         });
         
-        try (final TraceScope scope = Trace.startSpan("test span", sampler)) {
+        try (final TraceScope scope = tracer.newScope("test span")) {
             assertThat(service.getBooks().size(), equalTo(2));
-            assertThat(Trace.isTracing(), equalTo(true));
+            assertThat(Tracer.getCurrentSpan(), not(nullValue()));
             
             assertThat(TestSpanReceiver.getAllSpans().size(), equalTo(2));
             assertThat(TestSpanReceiver.getAllSpans().get(0).getDescription(), equalTo("Get Books"));
@@ -178,7 +170,6 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
         assertThat(TestSpanReceiver.getAllSpans().get(2).getDescription(), equalTo("test span"));
         
         final Map<String, List<String>> response = getResponseHeaders(service);
-        assertThat(response.get(TracerHeaders.DEFAULT_HEADER_TRACE_ID), not(nullValue()));
         assertThat(response.get(TracerHeaders.DEFAULT_HEADER_SPAN_ID), not(nullValue()));
     }
     
@@ -218,5 +209,16 @@ public class HTraceTracingTest extends AbstractBusClientServerTestBase {
     private Map<String, List<String>> getResponseHeaders(final BookStoreService service) {
         final Client proxy = ClientProxy.getClient(service);
         return CastUtils.cast((Map<?, ?>)proxy.getResponseContext().get(Message.PROTOCOL_HEADERS));
-    }    
+    }
+    
+    private static Tracer createTracer() {
+        final Map<String, String> properties = new HashMap<String, String>();
+        properties.put(Tracer.SPAN_RECEIVER_CLASSES_KEY, TestSpanReceiver.class.getName());
+        properties.put(Tracer.SAMPLER_CLASSES_KEY, AlwaysSampler.class.getName());
+        
+        return new Tracer.Builder()
+            .name("tracer")
+            .conf(HTraceConfiguration.fromMap(properties))
+            .build();
+    }
 }


Mime
View raw message