From a1eaa4e08d752a6a06885391c60c3d4539a4ce6e Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Sun, 26 May 2024 18:24:53 -0400 Subject: [PATCH] CXF-8969: Update to Brave 6 --- .../samples/jax_rs/tracing_brave/pom.xml | 12 +- .../jaxrs/tracing/server/CatalogTracing.java | 9 +- distribution/src/main/release/samples/pom.xml | 3 +- .../brave/AbstractBraveClientProvider.java | 42 ++--- .../tracing/brave/AbstractBraveProvider.java | 25 ++- .../cxf/tracing/brave/BraveClientFeature.java | 3 +- .../brave/BraveClientStartInterceptor.java | 2 +- .../brave/BraveClientStopInterceptor.java | 8 +- .../cxf/tracing/brave/BraveFeature.java | 1 - .../tracing/brave/BraveStopInterceptor.java | 3 +- ...rser.java => HttpClientRequestParser.java} | 19 +- ...ser.java => HttpClientResponseParser.java} | 21 +-- .../brave/internal/HttpAdapterFactory.java | 18 +- .../internal/HttpClientAdapterFactory.java | 101 +++++++---- .../internal/HttpServerAdapterFactory.java | 65 +++---- .../brave/jaxrs/BraveClientProvider.java | 9 +- .../cxf/tracing/brave/jaxrs/BraveFeature.java | 3 - .../tracing/brave/jaxrs/BraveProvider.java | 3 +- .../cxf/tracing/brave/BraveTraceTest.java | 24 +-- parent/pom.xml | 10 +- ...java => SpringJaxrsObservabilityTest.java} | 11 +- ...a => SpringJaxrsWebObservabilityTest.java} | 11 +- .../boot/SpringJaxwsObservabilityTest.java | 7 +- .../org/apache/cxf/systest/brave/HasSpan.java | 21 ++- .../systest/brave/IsAnnotationContaining.java | 9 +- ...SpanReporter.java => TestSpanHandler.java} | 15 +- .../brave/jaxrs/AbstractBraveTracingTest.java | 162 +++++++++--------- .../brave/jaxws/AbstractBraveTracingTest.java | 74 ++++---- .../jaxrs/tracing/brave/BraveTracingTest.java | 4 +- .../micrometer/MicrometerTracingTest.java | 4 +- .../jaxws/tracing/brave/BookStore.java | 4 +- .../jaxws/tracing/brave/BraveTracingTest.java | 6 +- .../micrometer/MicrometerTracingTest.java | 6 +- 33 files changed, 379 insertions(+), 336 deletions(-) rename integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/{HttpClientSpanParser.java => HttpClientRequestParser.java} (65%) rename integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/{HttpServerSpanParser.java => HttpClientResponseParser.java} (62%) rename systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/{SpringJaxrsObservabiityTest.java => SpringJaxrsObservabilityTest.java} (96%) rename systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/{SpringJaxrsWebObservabiityTest.java => SpringJaxrsWebObservabilityTest.java} (96%) rename systests/tracing/src/test/java/org/apache/cxf/systest/brave/{TestSpanReporter.java => TestSpanHandler.java} (72%) diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml index 6d674208475..d5276f4d213 100644 --- a/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml +++ b/distribution/src/main/release/samples/jax_rs/tracing_brave/pom.xml @@ -194,7 +194,17 @@ io.zipkin.reporter2 zipkin-sender-okhttp3 - 2.17.1 + ${cxf.zipkin-reporter.version} + + + io.zipkin.reporter2 + zipkin-reporter + ${cxf.zipkin-reporter.version} + + + io.zipkin.reporter2 + zipkin-reporter-brave + ${cxf.zipkin-reporter.version} io.zipkin.brave diff --git a/distribution/src/main/release/samples/jax_rs/tracing_brave/src/main/java/demo/jaxrs/tracing/server/CatalogTracing.java b/distribution/src/main/release/samples/jax_rs/tracing_brave/src/main/java/demo/jaxrs/tracing/server/CatalogTracing.java index 818ffe08c16..eac0b7175c9 100644 --- a/distribution/src/main/release/samples/jax_rs/tracing_brave/src/main/java/demo/jaxrs/tracing/server/CatalogTracing.java +++ b/distribution/src/main/release/samples/jax_rs/tracing_brave/src/main/java/demo/jaxrs/tracing/server/CatalogTracing.java @@ -25,12 +25,13 @@ import brave.propagation.ThreadLocalCurrentTraceContext; import zipkin2.Span; import zipkin2.reporter.AsyncReporter; -import zipkin2.reporter.Sender; +import zipkin2.reporter.BytesMessageSender; +import zipkin2.reporter.brave.ZipkinSpanHandler; import zipkin2.reporter.okhttp3.OkHttpSender; public class CatalogTracing implements AutoCloseable { private volatile AsyncReporter reporter; - private volatile Sender sender; + private volatile BytesMessageSender sender; private volatile HttpTracing httpTracing; private final String serviceName; @@ -74,10 +75,10 @@ private static HttpTracing createHttpTracing(String serviceName, AsyncReporter9.10.0 5.0.0 1.9.22.1 - 5.17.0 + 6.0.3 + 3.4.0 2.1 2.31.0 2.2.224 diff --git a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveClientProvider.java b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveClientProvider.java index 4071d0ca72c..dde2101af35 100644 --- a/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveClientProvider.java +++ b/integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/AbstractBraveClientProvider.java @@ -19,19 +19,16 @@ package org.apache.cxf.tracing.brave; import java.net.URI; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.logging.Logger; import brave.Span; import brave.Tracer.SpanInScope; -import brave.http.HttpClientAdapter; import brave.http.HttpClientHandler; import brave.http.HttpClientRequest; import brave.http.HttpClientResponse; import brave.http.HttpTracing; -import brave.propagation.Propagation.Setter; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.phase.PhaseInterceptorChain; import org.apache.cxf.tracing.AbstractTracingProvider; @@ -54,15 +51,10 @@ protected TraceScopeHolder startTraceSpan(final Map adapter = HttpClientAdapterFactory.create(request); + final HttpClientRequest wrapper = HttpClientAdapterFactory.create(request); - final HttpClientHandler handler = HttpClientHandler.create(brave, adapter); - final Span span = handler.handleSend( - brave - .tracing() - .propagation() - .injector(inject(requestHeaders)), - request); + final HttpClientHandler handler = HttpClientHandler.create(brave); + final Span span = handler.handleSend(wrapper); // 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. @@ -73,20 +65,13 @@ protected TraceScopeHolder startTraceSpan(final Map(new TraceScope(span, scope), scope == null /* detached */); } - - private Setter inject(final Map> requestHeaders) { - return (carrier, key, value) -> { - if (!requestHeaders.containsKey(key)) { - requestHeaders.put(key, Collections.singletonList(value)); - } - }; - } private boolean isAsyncInvocation() { return !PhaseInterceptorChain.getCurrentMessage().getExchange().isSynchronous(); } - protected void stopTraceSpan(final TraceScopeHolder holder, final int responseStatus) { + protected void stopTraceSpan(final TraceScopeHolder holder, final String method, + final URI uri, final int responseStatus) { if (holder == null) { return; } @@ -100,18 +85,19 @@ protected void stopTraceSpan(final TraceScopeHolder holder, final in brave.tracing().tracer().joinSpan(scope.getSpan().context()); } - final Response response = HttpAdapterFactory.response(responseStatus); - final HttpClientAdapter adapter = HttpClientAdapterFactory.create(response); + final Response response = HttpAdapterFactory.response(method, uri.toASCIIString(), responseStatus); + final HttpClientResponse wrapper = HttpClientAdapterFactory.create(response); - final HttpClientHandler handler = HttpClientHandler.create(brave, adapter); - handler.handleReceive(response, null, scope.getSpan()); + final HttpClientHandler handler = HttpClientHandler.create(brave); + handler.handleReceive(wrapper, scope.getSpan()); } finally { scope.close(); } } } - protected void stopTraceSpan(final TraceScopeHolder holder, final Throwable ex) { + protected void stopTraceSpan(final TraceScopeHolder holder, final String method, + final URI uri, final Throwable ex) { if (holder == null) { return; } @@ -125,9 +111,9 @@ protected void stopTraceSpan(final TraceScopeHolder holder, final Th brave.tracing().tracer().joinSpan(scope.getSpan().context()); } - final HttpClientHandler handler = - HttpClientHandler.create(brave); - handler.handleReceive(null, ex, scope.getSpan()); + final HttpClientResponse wrapper = HttpClientAdapterFactory.create(method, uri, ex); + final HttpClientHandler handler = HttpClientHandler.create(brave); + handler.handleReceive(wrapper, scope.getSpan()); } finally { scope.close(); } 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 index d991f780aa2..ea332a3b813 100644 --- 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 @@ -25,8 +25,9 @@ import brave.Span; import brave.Tracer.SpanInScope; -import brave.http.HttpServerAdapter; import brave.http.HttpServerHandler; +import brave.http.HttpServerRequest; +import brave.http.HttpServerResponse; import brave.http.HttpTracing; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.phase.PhaseInterceptorChain; @@ -50,16 +51,10 @@ protected TraceScopeHolder startTraceSpan(final Map adapter = HttpServerAdapterFactory.create(request); + final HttpServerRequest wrapper = HttpServerAdapterFactory.create(request); - final HttpServerHandler handler = HttpServerHandler.create(brave, adapter); - - Span span = handler.handleReceive( - brave - .tracing() - .propagation() - .extractor(adapter::requestHeader), - request); + final HttpServerHandler handler = HttpServerHandler.create(brave); + Span span = handler.handleReceive(wrapper); // If the service resource is using asynchronous processing mode, the trace // scope will be closed in another thread and as such should be detached. @@ -76,6 +71,8 @@ protected TraceScopeHolder startTraceSpan(final Map> requestHeaders, final Map> responseHeaders, + final String method, + final URI uri, final int responseStatus, final TraceScopeHolder holder) { if (holder == null) { @@ -93,11 +90,11 @@ protected void stopTraceSpan(final Map> requestHeaders, span = brave.tracing().tracer().joinSpan(scope.getSpan().context()); } - final Response response = HttpAdapterFactory.response(responseStatus); - final HttpServerAdapter adapter = HttpServerAdapterFactory.create(response); + final Response response = HttpAdapterFactory.response(method, uri.getPath(), responseStatus); + final HttpServerResponse wrapper = HttpServerAdapterFactory.create(response); - final HttpServerHandler handler = HttpServerHandler.create(brave, adapter); - handler.handleSend(response, null, scope.getSpan()); + final HttpServerHandler handler = HttpServerHandler.create(brave); + handler.handleSend(wrapper, scope.getSpan()); } finally { scope.close(); if (span != null) { 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 index 8d0fd6ea406..3fbbd45e4d7 100644 --- 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 @@ -48,7 +48,8 @@ public Portable(final Tracing tracing) { this( HttpTracing .newBuilder(tracing) - .clientParser(new HttpClientSpanParser()) + .clientRequestParser(new HttpClientRequestParser()) + .clientResponseParser(new HttpClientResponseParser()) .build() ); } 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 index d33c4ad1fe1..a57d9742c87 100644 --- 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 @@ -52,6 +52,6 @@ public void handleFault(Message message) { (TraceScopeHolder)message.getExchange().get(TRACE_SPAN); final Exception ex = message.getContent(Exception.class); - super.stopTraceSpan(holder, ex); + super.stopTraceSpan(holder, (String) message.get(Message.HTTP_REQUEST_METHOD), getUri(message), ex); } } 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 index 016e1087fa1..c754cf508a8 100644 --- 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 @@ -21,6 +21,7 @@ import brave.http.HttpTracing; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageUtils; import org.apache.cxf.phase.Phase; public class BraveClientStopInterceptor extends AbstractBraveClientInterceptor { @@ -43,6 +44,11 @@ public void handleMessage(Message message) throws Fault { responseCode = 200; } - super.stopTraceSpan(holder, responseCode); + boolean isRequestor = MessageUtils.isRequestor(message); + final Message requestMessage = isRequestor ? message.getExchange().getOutMessage() + : message.getExchange().getInMessage(); + + super.stopTraceSpan(holder, (String) requestMessage.get(Message.HTTP_REQUEST_METHOD), + getUri(requestMessage), responseCode); } } 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 index 90d69e7c1d0..4d152a01178 100644 --- 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 @@ -83,7 +83,6 @@ public void doInitializeProvider(InterceptorProvider provider, Bus bus) { private static HttpTracing newTracer(Tracing tracing) { return HttpTracing .newBuilder(tracing) - .serverParser(new HttpServerSpanParser()) .build(); } 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 index 7dc4c0a3885..ceb6a05da7e 100644 --- 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 @@ -60,6 +60,7 @@ public void handleMessage(Message message) throws Fault { responseCode = 200; } - super.stopTraceSpan(requestHeaders, responseHeaders, responseCode, holder); + super.stopTraceSpan(requestHeaders, responseHeaders, (String)requestMessage.get(Message.HTTP_REQUEST_METHOD), + getUri(requestMessage), responseCode, holder); } } 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/HttpClientRequestParser.java similarity index 65% rename from integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientSpanParser.java rename to integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientRequestParser.java index 7fc959761af..90d131ce2cc 100644 --- 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/HttpClientRequestParser.java @@ -18,20 +18,17 @@ */ package org.apache.cxf.tracing.brave; -import brave.http.HttpAdapter; -import brave.http.HttpClientParser; +import brave.http.HttpRequest; +import brave.http.HttpRequestParser; +import brave.propagation.TraceContext; import org.apache.cxf.common.util.StringUtils; -public class HttpClientSpanParser extends HttpClientParser { +public class HttpClientRequestParser extends HttpRequestParser.Default { @Override - protected String spanName(HttpAdapter 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; + protected String spanName(HttpRequest req, TraceContext context) { + if (StringUtils.isEmpty(req.url())) { + return req.method(); } - return method + " " + path; + return req.method() + " " + req.url(); } } 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/HttpClientResponseParser.java similarity index 62% rename from integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpServerSpanParser.java rename to integration/tracing/tracing-brave/src/main/java/org/apache/cxf/tracing/brave/HttpClientResponseParser.java index fd609639290..94ed0eb8b06 100644 --- 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/HttpClientResponseParser.java @@ -18,20 +18,17 @@ */ package org.apache.cxf.tracing.brave; -import brave.http.HttpAdapter; -import brave.http.HttpServerParser; -import org.apache.cxf.common.util.StringUtils; +import brave.SpanCustomizer; +import brave.Tags; +import brave.http.HttpResponseParser; -public class HttpServerSpanParser extends HttpServerParser { +public class HttpClientResponseParser extends HttpResponseParser.Default { @Override - protected String spanName(HttpAdapter 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; + protected void error(int httpStatus, Throwable error, SpanCustomizer span) { + if (error != null) { + span.tag(Tags.ERROR.key(), error.getMessage()); + } else { + super.error(httpStatus, error, span); } - return method + " " + path; } } 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 index 49413691798..176780f1252 100644 --- 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 @@ -48,12 +48,24 @@ String method() { } final class Response { + private final String method; + private final String path; private final Integer status; - Response(Integer status) { + Response(String method, String path, Integer status) { + this.method = method; + this.path = path; this.status = status; } + String path() { + return path; + } + + String method() { + return method; + } + Integer status() { return status; } @@ -63,7 +75,7 @@ static Request request(Map> headers, URI uri, String method return new Request(headers, uri, method); } - static Response response(Integer status) { - return new Response(status); + static Response response(String method, String path, Integer status) { + return new Response(method, path, status); } } 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 index 74996480822..6ad39b4eeee 100644 --- 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 @@ -18,71 +18,102 @@ */ package org.apache.cxf.tracing.brave.internal; +import java.net.URI; import java.util.List; -import brave.http.HttpClientAdapter; +import brave.http.HttpClientRequest; +import brave.http.HttpClientResponse; public interface HttpClientAdapterFactory extends HttpAdapterFactory { - static HttpClientAdapter create(Request request) { - return new HttpClientAdapter() { + static HttpClientRequest create(Request request) { + return new HttpClientRequest() { @Override - public String method(Request request) { + public String method() { return request.method(); } @Override - public String path(Request request) { + public String path() { return request.uri().getPath(); } + @Override + public String route() { + return path(); + } + @Override - public String url(Request request) { + public String url() { return request.uri().toString(); } @Override - public String requestHeader(Request request, String name) { + public String header(String name) { List value = request.headers().get(name); - - if (value != null && !value.isEmpty()) { - return value.get(0); - } - - return null; + return (value != null && !value.isEmpty()) ? value.get(0) : null; } - @Override - public Integer statusCode(Response response) { - throw new UnsupportedOperationException("The operation is not supported for request adapter"); + @Override + public Request unwrap() { + return request; + } + + @Override + public void header(String name, String value) { + request.headers().put(name, List.of(value)); } }; } - static HttpClientAdapter create(Response response) { - return new HttpClientAdapter() { - @Override - public String method(Request request) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + static HttpClientResponse create(Response response) { + return new HttpClientResponse() { + @Override + public String route() { + return response.path(); } - + @Override - public String path(Request request) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + public int statusCode() { + return response.status(); } - - @Override - public String url(Request request) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + + @Override + public Response unwrap() { + return response; } - - @Override - public String requestHeader(Request request, String name) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + + @Override + public String method() { + return response.method(); } + }; + } - @Override - public Integer statusCode(Response response) { - return response.status(); + static HttpClientResponse create(String method, URI uri, Throwable ex) { + return new HttpClientResponse() { + @Override + public Throwable unwrap() { + return ex; + } + + @Override + public String method() { + return method; + } + + @Override + public String route() { + return uri.toASCIIString(); + } + + @Override + public int statusCode() { + return 0; + } + + @Override + public Throwable error() { + return ex; } }; } 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 index 69fee0f1e43..1006c3ad597 100644 --- 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 @@ -20,28 +20,34 @@ import java.util.List; -import brave.http.HttpServerAdapter; +import brave.http.HttpServerRequest; +import brave.http.HttpServerResponse; public interface HttpServerAdapterFactory extends HttpAdapterFactory { - static HttpServerAdapter create(Request request) { - return new HttpServerAdapter() { + static HttpServerRequest create(Request request) { + return new HttpServerRequest() { @Override - public String method(Request request) { + public String method() { return request.method(); } @Override - public String path(Request request) { + public String path() { return request.uri().getPath(); } + + @Override + public String route() { + return path(); + } @Override - public String url(Request request) { + public String url() { return request.uri().toString(); } @Override - public String requestHeader(Request request, String name) { + public String header(String name) { List value = request.headers().get(name); if (value != null && !value.isEmpty()) { @@ -50,40 +56,35 @@ public String requestHeader(Request request, String name) { return null; } - - @Override - public Integer statusCode(Response response) { - throw new UnsupportedOperationException("The operation is not supported for request adapter"); + + @Override + public Request unwrap() { + return request; } }; } - static HttpServerAdapter create(Response response) { - return new HttpServerAdapter() { - @Override - public String method(Request request) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + static HttpServerResponse create(Response response) { + return new HttpServerResponse() { + @Override + public String method() { + return response.method(); } - - @Override - public String path(Request request) { - throw new UnsupportedOperationException("The operation is not supported for response adapter"); + + @Override + public String route() { + return response.path(); } - + @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) { + public int statusCode() { return response.status(); } + + @Override + public Response unwrap() { + return response; + } }; } } 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 index 40fb949f888..db3a4be9f05 100644 --- 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 @@ -28,7 +28,8 @@ import jakarta.ws.rs.client.ClientResponseFilter; import jakarta.ws.rs.ext.Provider; import org.apache.cxf.tracing.brave.AbstractBraveClientProvider; -import org.apache.cxf.tracing.brave.HttpClientSpanParser; +import org.apache.cxf.tracing.brave.HttpClientRequestParser; +import org.apache.cxf.tracing.brave.HttpClientResponseParser; import org.apache.cxf.tracing.brave.TraceScope; @Provider @@ -39,7 +40,8 @@ public BraveClientProvider(final Tracing brave) { this( HttpTracing .newBuilder(brave) - .clientParser(new HttpClientSpanParser()) + .clientRequestParser(new HttpClientRequestParser()) + .clientResponseParser(new HttpClientResponseParser()) .build() ); } @@ -64,6 +66,7 @@ public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException { final TraceScopeHolder holder = (TraceScopeHolder)requestContext.getProperty(TRACE_SPAN); - super.stopTraceSpan(holder, responseContext.getStatus()); + super.stopTraceSpan(holder, requestContext.getMethod(), + requestContext.getUri(), responseContext.getStatus()); } } 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 index 951333d767f..798946124b6 100644 --- 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 @@ -25,7 +25,6 @@ import jakarta.ws.rs.core.Feature; import jakarta.ws.rs.core.FeatureContext; import jakarta.ws.rs.ext.Provider; -import org.apache.cxf.tracing.brave.HttpServerSpanParser; @Provider public class BraveFeature implements Feature { @@ -39,7 +38,6 @@ public BraveFeature(final String name) { this( HttpTracing .newBuilder(Tracing.newBuilder().localServiceName(name).build()) - .serverParser(new HttpServerSpanParser()) .build() ); } @@ -48,7 +46,6 @@ public BraveFeature(final Tracing tracing) { this( HttpTracing .newBuilder(tracing) - .serverParser(new HttpServerSpanParser()) .build() ); } 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 index 0d4a5a61799..9c498fa2b57 100644 --- 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 @@ -58,7 +58,8 @@ public void filter(final ContainerRequestContext requestContext) throws IOExcept public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException { super.stopTraceSpan(requestContext.getHeaders(), responseContext.getHeaders(), - responseContext.getStatus(), (TraceScopeHolder)requestContext.getProperty(TRACE_SPAN)); + requestContext.getMethod(), requestContext.getUriInfo().getRequestUri(), + responseContext.getStatus(), (TraceScopeHolder)requestContext.getProperty(TRACE_SPAN)); } @Override 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 index 7a90ef67666..5028e225ec1 100644 --- 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 @@ -23,12 +23,13 @@ import java.util.List; import brave.Tracing; +import brave.handler.MutableSpan; +import brave.handler.SpanHandler; +import brave.propagation.TraceContext; 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 zipkin2.Span; -import zipkin2.reporter.Reporter; import org.junit.After; import org.junit.Assert; @@ -56,7 +57,7 @@ public void startServer() { public void testMyService() { MyService myService = createProxy(clientLogging); myService.echo("test"); - for (Span span : localReporter.spans) { + for (MutableSpan span : localReporter.spans) { System.out.println(span); } Assert.assertEquals(2, localReporter.spans.size()); @@ -84,26 +85,25 @@ private static MyService createProxy(Feature trace) { return (MyService)factory.create(); } - private static BraveFeature createLoggingFeature(Reporter reporter) { + private static BraveFeature createLoggingFeature(SpanHandler handler) { Tracing brave = - Tracing.newBuilder().localServiceName("myservice").spanReporter(reporter).build(); + Tracing.newBuilder().localServiceName("myservice").addSpanHandler(handler).build(); return new BraveFeature(brave); } - private static BraveClientFeature createClientLoggingFeature(Reporter reporter) { + private static BraveClientFeature createClientLoggingFeature(SpanHandler handler) { Tracing brave = - Tracing.newBuilder().localServiceName("myservice").spanReporter(reporter).build(); + Tracing.newBuilder().localServiceName("myservice").addSpanHandler(handler).build(); return new BraveClientFeature(brave); } - static final class Localreporter implements Reporter { - List spans = new ArrayList<>(); + static final class Localreporter extends SpanHandler { + List spans = new ArrayList<>(); @Override - public void report(Span span) { - spans.add(span); + public boolean end(TraceContext context, MutableSpan span, Cause cause) { + return spans.add(span); } - } } diff --git a/parent/pom.xml b/parent/pom.xml index d81bd1feb64..db77dc3d785 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -97,7 +97,7 @@ [3.0, 4.0) 3.0.8 1.77 - 5.17.1 + 6.0.3 4.0.1 4.8.25 1.5.1 @@ -178,8 +178,8 @@ 1.5.6 9.10.0 3.9.6 - 1.13.0 - 1.2.6 + 1.13.1 + 1.3.1 3.1 3.0.1 3.1.1 @@ -192,7 +192,7 @@ 2.0.46.Final 2.0.12 3.2.2 - 1.34.1 + 1.39.0 1.25.0-alpha 0.33.0 2.0.27 @@ -241,7 +241,7 @@ 2.3.1 3.8.15.Final 2.1 - 2.17.2 + 3.4.0 1.0.1 diff --git a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabilityTest.java similarity index 96% rename from systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java rename to systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabilityTest.java index 747218a0501..de3b42e4e5d 100644 --- a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabiityTest.java +++ b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsObservabilityTest.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; +import brave.handler.SpanHandler; import brave.sampler.Sampler; import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.client.WebTarget; @@ -43,8 +44,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import zipkin2.Span; -import zipkin2.reporter.Reporter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; @@ -60,10 +59,10 @@ import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.hasSize; -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabiityTest.TestConfig.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsObservabilityTest.TestConfig.class) @ActiveProfiles("jaxrs") @AutoConfigureObservability -public class SpringJaxrsObservabiityTest { +public class SpringJaxrsObservabilityTest { @Autowired private MeterRegistry registry; @@ -101,8 +100,8 @@ ArrayListSpanReporter arrayListSpanReporter() { } @Bean - Reporter reporter() { - return Reporter.CONSOLE; + SpanHandler spanHandler() { + return SpanHandler.NOOP; } } diff --git a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabiityTest.java b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabilityTest.java similarity index 96% rename from systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabiityTest.java rename to systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabilityTest.java index d1f07d096db..a553f6a6838 100644 --- a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabiityTest.java +++ b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxrs/spring/boot/SpringJaxrsWebObservabilityTest.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider; +import brave.handler.SpanHandler; import brave.sampler.Sampler; import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.client.WebTarget; @@ -42,8 +43,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; -import zipkin2.Span; -import zipkin2.reporter.Reporter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; @@ -59,10 +58,10 @@ import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.hasSize; -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsWebObservabiityTest.TestConfig.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = SpringJaxrsWebObservabilityTest.TestConfig.class) @ActiveProfiles("jaxrs") @AutoConfigureObservability -public class SpringJaxrsWebObservabiityTest { +public class SpringJaxrsWebObservabilityTest { @Autowired private MeterRegistry registry; @@ -100,8 +99,8 @@ ArrayListSpanReporter arrayListSpanReporter() { } @Bean - Reporter reporter() { - return Reporter.CONSOLE; + SpanHandler spanHandler() { + return SpanHandler.NOOP; } } diff --git a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsObservabilityTest.java b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsObservabilityTest.java index 436cd5caae7..5858a823691 100644 --- a/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsObservabilityTest.java +++ b/systests/spring-boot/src/test/java/org/apache/cxf/systest/jaxws/spring/boot/SpringJaxwsObservabilityTest.java @@ -28,6 +28,7 @@ import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; +import brave.handler.SpanHandler; import brave.sampler.Sampler; import jakarta.xml.ws.Dispatch; import jakarta.xml.ws.Endpoint; @@ -50,8 +51,6 @@ import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.context.annotation.Bean; import org.springframework.test.context.ActiveProfiles; -import zipkin2.Span; -import zipkin2.reporter.Reporter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; @@ -139,8 +138,8 @@ ArrayListSpanReporter arrayListSpanReporter() { } @Bean - Reporter reporter() { - return Reporter.CONSOLE; + SpanHandler spanHandler() { + return SpanHandler.NOOP; } } diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/HasSpan.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/HasSpan.java index d51ea74d41a..ed50864a04e 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/HasSpan.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/HasSpan.java @@ -18,20 +18,22 @@ */ package org.apache.cxf.systest.brave; +import java.util.Map; +import java.util.stream.Collectors; + +import brave.handler.MutableSpan; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.hamcrest.core.IsIterableContaining; -import zipkin2.Annotation; -import zipkin2.Span; -public class HasSpan extends IsIterableContaining { +public class HasSpan extends IsIterableContaining { public HasSpan(final String name) { this(name, null); } - public HasSpan(final String name, final Matcher> matcher) { - super(new TypeSafeMatcher() { + public HasSpan(final String name, final Matcher> matcher) { + super(new TypeSafeMatcher() { @Override public void describeTo(Description description) { description @@ -46,13 +48,16 @@ public void describeTo(Description description) { } @Override - protected boolean matchesSafely(Span item) { + protected boolean matchesSafely(MutableSpan item) { if (!name.equals(item.name())) { return false; } if (matcher != null) { - return matcher.matches(item.annotations()); + return matcher.matches(item.annotations() + .stream() + .map(Map.Entry::getValue) + .collect(Collectors.toList())); } return true; @@ -64,7 +69,7 @@ public static HasSpan hasSpan(final String name) { return new HasSpan(name); } - public static HasSpan hasSpan(final String name, final Matcher> matcher) { + public static HasSpan hasSpan(final String name, final Matcher> matcher) { return new HasSpan(name, matcher); } } \ No newline at end of file diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/IsAnnotationContaining.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/IsAnnotationContaining.java index ac8ed1c09e6..1b82a2f71ec 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/IsAnnotationContaining.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/IsAnnotationContaining.java @@ -21,11 +21,10 @@ import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; import org.hamcrest.core.IsIterableContaining; -import zipkin2.Annotation; -public class IsAnnotationContaining extends IsIterableContaining { +public class IsAnnotationContaining extends IsIterableContaining { public IsAnnotationContaining(final String value) { - super(new TypeSafeMatcher() { + super(new TypeSafeMatcher() { @Override public void describeTo(Description description) { description @@ -34,8 +33,8 @@ public void describeTo(Description description) { } @Override - protected boolean matchesSafely(Annotation item) { - return value.equals(item.value()); + protected boolean matchesSafely(String item) { + return value.equals(item); } }); } diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanReporter.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanHandler.java similarity index 72% rename from systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanReporter.java rename to systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanHandler.java index d15fda52e0a..266cc366379 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanReporter.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/TestSpanHandler.java @@ -21,18 +21,19 @@ import java.util.ArrayList; import java.util.List; -import zipkin2.Span; -import zipkin2.reporter.Reporter; +import brave.handler.MutableSpan; +import brave.handler.SpanHandler; +import brave.propagation.TraceContext; -public class TestSpanReporter implements Reporter { - private static final List SPANS = new ArrayList<>(12); +public class TestSpanHandler extends SpanHandler { + private static final List SPANS = new ArrayList<>(12); @Override - public void report(Span span) { - SPANS.add(span); + public boolean end(TraceContext context, MutableSpan span, Cause cause) { + return SPANS.add(span); } - public static List getAllSpans() { + public static List getAllSpans() { return SPANS; } diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java index faa149cd819..0a248da9e77 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxrs/AbstractBraveTracingTest.java @@ -40,7 +40,7 @@ import org.apache.cxf.feature.Feature; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.systest.brave.BraveTestSupport.SpanId; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.testutil.common.AbstractClientServerTestBase; import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; @@ -73,13 +73,13 @@ public abstract class AbstractBraveTracingTest extends AbstractClientServerTestB public ExpectedException expectedException = ExpectedException.none(); private final Tracing brave = Tracing.newBuilder() - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); @After public void tearDown() { - TestSpanReporter.clear(); + TestSpanHandler.clear(); } @Test @@ -87,9 +87,9 @@ public void testThatNewSpanIsCreatedWhenNotProvided() { final Response r = createWebClient("/bookstore/books").get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books")); assertFalse(r.getHeaders().containsKey(SPAN_ID_NAME)); assertFalse(r.getHeaders().containsKey(TRACE_ID_NAME)); @@ -104,9 +104,9 @@ public void testThatNewInnerSpanIsCreated() { final Response r = withTrace(createWebClient("/bookstore/books"), spanId).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books")); } @Test @@ -116,9 +116,9 @@ public void testThatCurrentSpanIsAnnotatedWithKeyValue() { final Response r = withTrace(createWebClient("/bookstore/book/1"), spanId).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/book/1")); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("book-id", "1")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET /bookstore/book/1")); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasEntry("book-id", "1")); } @Test @@ -128,9 +128,9 @@ public void testThatParallelSpanIsAnnotatedWithTimeline() { final Response r = withTrace(createWebClient("/bookstore/process"), spanId).put(""); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans(), hasSpan("processing books", hasItem("Processing started"))); - assertThat(TestSpanReporter.getAllSpans(), hasSpan("put /bookstore/process")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans(), hasSpan("Processing books", hasItem("Processing started"))); + assertThat(TestSpanHandler.getAllSpans(), hasSpan("PUT /bookstore/process")); } @Test @@ -138,9 +138,9 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvided() { final Response r = createWebClient("/bookstore/books", getClientProvider(brave)).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue())); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), not(nullValue())); } @Test @@ -150,12 +150,12 @@ public void testThatNewInnerSpanIsCreatedUsingAsyncInvocation() { final Response r = withTrace(createWebClient("/bookstore/books/async"), spanId).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/async")); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books")); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue())); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), - equalTo(TestSpanReporter.getAllSpans().get(1).id())); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books/async")); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Processing books")); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), not(nullValue())); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), + equalTo(TestSpanHandler.getAllSpans().get(1).id())); } @Test @@ -165,8 +165,8 @@ public void testThatOuterSpanIsCreatedUsingAsyncInvocation() { final Response r = withTrace(createWebClient("/bookstore/books/async/notrace"), spanId).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/books/async/notrace")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET /bookstore/books/async/notrace")); } @Test @@ -174,9 +174,9 @@ public void testThatNewSpanIsCreatedUsingAsyncInvocation() { final Response r = createWebClient("/bookstore/books/async").get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/async")); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books/async")); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Processing books")); } @Test @@ -187,10 +187,10 @@ public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exc final Response r = f.get(1, TimeUnit.SECONDS); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); - assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().get(2).name(), equalTo("GET " + client.getCurrentURI())); } @Test @@ -205,18 +205,18 @@ public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() .map(this::get) .forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus())); - assertThat(TestSpanReporter.getAllSpans().toString(), TestSpanReporter.getAllSpans().size(), equalTo(12)); + assertThat(TestSpanHandler.getAllSpans().toString(), TestSpanHandler.getAllSpans().size(), equalTo(12)); IntStream .range(0, 4) .map(index -> index * 3) .forEach(index -> { - assertThat(TestSpanReporter.getAllSpans().get(index).name(), - equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(), - equalTo("get /bookstore/books")); - assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(), - equalTo("get " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().get(index).name(), + equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(index + 1).name(), + equalTo("GET /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().get(index + 2).name(), + equalTo("GET " + client.getCurrentURI())); }); } @@ -231,18 +231,18 @@ public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() thro .mapToObj(index -> client.get()) .forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus())); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(12)); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(12)); IntStream .range(0, 4) .map(index -> index * 3) .forEach(index -> { - assertThat(TestSpanReporter.getAllSpans().get(index).name(), - equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(), - equalTo("get /bookstore/books")); - assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(), - equalTo("get " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().get(index).name(), + equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(index + 1).name(), + equalTo("GET /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().get(index + 2).name(), + equalTo("GET " + client.getCurrentURI())); }); } @@ -255,20 +255,20 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLExcep final Response r = client.get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue())); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); - assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), not(nullValue())); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().get(2).name(), equalTo("GET " + client.getCurrentURI())); } finally { span.finish(); } // Await till flush happens, usually a second is enough - await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanReporter.getAllSpans().size() == 4); + await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanHandler.getAllSpans().size() == 4); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4)); - assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(4)); + assertThat(TestSpanHandler.getAllSpans().get(3).name(), equalTo("test span")); } @Test @@ -283,19 +283,19 @@ public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws assertEquals(Status.OK.getStatusCode(), r.getStatus()); assertThat(brave.tracer().currentSpan().context().spanId(), equalTo(span.context().spanId())); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books")); - assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books")); + assertThat(TestSpanHandler.getAllSpans().get(2).name(), equalTo("GET " + client.getCurrentURI())); } finally { span.finish(); } // Await till flush happens, usually a second is enough - await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanReporter.getAllSpans().size() == 4); + await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanHandler.getAllSpans().size() == 4); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4)); - assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(4)); + assertThat(TestSpanHandler.getAllSpans().get(3).name(), equalTo("test span")); } @Test @@ -305,23 +305,23 @@ public void testThatInnerSpanIsCreatedUsingPseudoAsyncInvocation() { final Response r = withTrace(createWebClient("/bookstore/books/pseudo-async"), spanId).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/pseudo-async")); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books/pseudo-async")); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Processing books")); } @Test public void testThatNoSpansAreRecordedWhenNotSampled() { final Tracing never = Tracing .newBuilder() - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .sampler(Sampler.NEVER_SAMPLE) .build(); final Response r = createWebClient("/bookstore/books", getClientProvider(never)).get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(0)); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(0)); } @Test @@ -340,11 +340,11 @@ public void testThatNewSpanIsCreatedOnClientTimeout() { try { client.get(); } finally { - await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanReporter.getAllSpans().size() == 2); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get " + client.getCurrentURI())); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasKey("error")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/long")); + await().atMost(Duration.ofSeconds(1L)).until(()-> TestSpanHandler.getAllSpans().size() == 2); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET " + client.getCurrentURI())); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasKey("error")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("GET /bookstore/books/long")); } } @@ -353,9 +353,9 @@ public void testThatErrorSpanIsCreatedOnExceptionWhenNotProvided() { final Response r = createWebClient("/bookstore/books/exception").get(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/books/exception")); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("http.status_code", "500")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET /bookstore/books/exception")); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasEntry("http.status_code", "500")); assertFalse(r.getHeaders().containsKey(SPAN_ID_NAME)); assertFalse(r.getHeaders().containsKey(TRACE_ID_NAME)); @@ -368,9 +368,9 @@ public void testThatErrorSpanIsCreatedOnErrorWhenNotProvided() { final Response r = createWebClient("/bookstore/books/error").get(); assertEquals(Status.SERVICE_UNAVAILABLE.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/books/error")); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("http.status_code", "503")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET /bookstore/books/error")); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasEntry("http.status_code", "503")); assertFalse(r.getHeaders().containsKey(SPAN_ID_NAME)); assertFalse(r.getHeaders().containsKey(TRACE_ID_NAME)); @@ -383,9 +383,9 @@ public void testThatErrorSpanIsCreatedOnMappedExceptionWhenNotProvided() { final Response r = createWebClient("/bookstore/books/mapper").get(); assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus()); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get /bookstore/books/mapper")); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("http.status_code", "404")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("GET /bookstore/books/mapper")); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasEntry("http.status_code", "404")); assertFalse(r.getHeaders().containsKey(SPAN_ID_NAME)); assertFalse(r.getHeaders().containsKey(TRACE_ID_NAME)); diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxws/AbstractBraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxws/AbstractBraveTracingTest.java index e17b0eb08de..07991044f4e 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxws/AbstractBraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/brave/jaxws/AbstractBraveTracingTest.java @@ -39,7 +39,7 @@ import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.message.Message; import org.apache.cxf.systest.brave.BraveTestSupport.SpanId; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.jaxws.tracing.BookStoreService; import org.apache.cxf.testutil.common.AbstractClientServerTestBase; @@ -64,9 +64,9 @@ public void testThatNewSpanIsCreatedWhenNotProvided() throws Exception { final BookStoreService service = createJaxWsService(); assertThat(service.getBooks().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("post /bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("POST /BookStore")); final Map> headers = getResponseHeaders(service); assertFalse(headers.containsKey(TRACE_ID_NAME)); @@ -94,9 +94,9 @@ public void testThatNewInnerSpanIsCreated() throws Exception { final BookStoreService service = createJaxWsService(headers); assertThat(service.getBooks().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("post /bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("POST /BookStore")); } @Test @@ -105,12 +105,12 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvided() throws Exception final BookStoreService service = createJaxWsService(getClientFeature(brave)); assertThat(service.getBooks().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue())); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("post /bookstore")); - assertThat(TestSpanReporter.getAllSpans().get(2).name(), - equalTo("post http://localhost:" + getPort() + "/bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), not(nullValue())); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("POST /BookStore")); + assertThat(TestSpanHandler.getAllSpans().get(2).name(), + equalTo("POST http://localhost:" + getPort() + "/BookStore")); } } @@ -125,12 +125,12 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws Exception { assertThat(service.getBooks().size(), equalTo(2)); assertThat(brave.tracer().currentSpan(), not(nullValue())); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books")); - assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue())); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("post /bookstore")); - assertThat(TestSpanReporter.getAllSpans().get(2).name(), - equalTo("post http://localhost:" + getPort() + "/bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(3)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("Get Books")); + assertThat(TestSpanHandler.getAllSpans().get(0).parentId(), not(nullValue())); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), equalTo("POST /BookStore")); + assertThat(TestSpanHandler.getAllSpans().get(2).name(), + equalTo("POST http://localhost:" + getPort() + "/BookStore")); } } finally { if (span != null) { @@ -138,8 +138,8 @@ public void testThatProvidedSpanIsNotClosedWhenActive() throws Exception { } } - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4)); - assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(4)); + assertThat(TestSpanHandler.getAllSpans().get(3).name(), equalTo("test span")); } } @@ -154,8 +154,8 @@ public void testThatNewSpanIsCreatedInCaseOfFault() throws Exception { /* expected exception */ } - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(1)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("post /bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(1)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("POST /BookStore")); final Map> headers = getResponseHeaders(service); assertFalse(headers.containsKey(TRACE_ID_NAME)); @@ -176,10 +176,10 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvidedInCaseOfFault() thr /* expected exception */ } - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("post /bookstore")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), - equalTo("post http://localhost:" + getPort() + "/bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("POST /BookStore")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), + equalTo("POST http://localhost:" + getPort() + "/BookStore")); } } @@ -189,11 +189,11 @@ public void testThatNewChildSpanIsCreatedWhenParentIsProvidedAndCustomStatusCode final BookStoreService service = createJaxWsService(getClientFeature(brave)); service.addBooks(); - assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2)); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("post /bookstore")); - assertThat(TestSpanReporter.getAllSpans().get(0).tags(), hasEntry("http.status_code", "305")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), - equalTo("post http://localhost:" + getPort() + "/bookstore")); + assertThat(TestSpanHandler.getAllSpans().size(), equalTo(2)); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("POST /BookStore")); + assertThat(TestSpanHandler.getAllSpans().get(0).tags(), hasEntry("http.status_code", "305")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), + equalTo("POST http://localhost:" + getPort() + "/BookStore")); } } @@ -204,11 +204,11 @@ public void testThatNewInnerSpanIsCreatedOneway() throws Exception { service.orderBooks(); // Await till flush happens, usually every second - await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanReporter.getAllSpans().size() == 2); + await().atMost(Duration.ofSeconds(1L)).until(() -> TestSpanHandler.getAllSpans().size() == 2); - assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("post /bookstore")); - assertThat(TestSpanReporter.getAllSpans().get(1).name(), - equalTo("post http://localhost:" + getPort() + "/bookstore")); + assertThat(TestSpanHandler.getAllSpans().get(0).name(), equalTo("POST /BookStore")); + assertThat(TestSpanHandler.getAllSpans().get(1).name(), + equalTo("POST http://localhost:" + getPort() + "/BookStore")); } } @@ -250,7 +250,7 @@ private static Map> getResponseHeaders(final BookStoreServi private static Tracing createTracer() { return Tracing.newBuilder() .localServiceName("book-store") - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); } diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java index 93e0a6e28b1..a757727a5ce 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/brave/BraveTracingTest.java @@ -24,7 +24,7 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.jaxrs.model.AbstractResourceInfo; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.brave.jaxrs.AbstractBraveTracingTest; import org.apache.cxf.systest.jaxrs.tracing.BookStore; import org.apache.cxf.systest.jaxrs.tracing.NullPointerExceptionMapper; @@ -48,7 +48,7 @@ public static class BraveServer extends AbstractTestServerBase { protected void run() { final Tracing brave = Tracing .newBuilder() - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/micrometer/MicrometerTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/micrometer/MicrometerTracingTest.java index 231c6b1671a..e682f4fa90c 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/micrometer/MicrometerTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxrs/tracing/micrometer/MicrometerTracingTest.java @@ -25,7 +25,7 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.jaxrs.model.AbstractResourceInfo; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.brave.jaxrs.AbstractBraveTracingTest; import org.apache.cxf.systest.jaxrs.tracing.BookStore; import org.apache.cxf.systest.jaxrs.tracing.NullPointerExceptionMapper; @@ -64,7 +64,7 @@ public static class MicrometerServer extends AbstractTestServerBase { protected void run() { final Tracing brave = Tracing .newBuilder() - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); final ObservationRegistry observationRegistry = createObservationRegistry(meterRegistry, brave); diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BookStore.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BookStore.java index d7acce256c2..3179e10adb6 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BookStore.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BookStore.java @@ -32,7 +32,7 @@ import jakarta.xml.ws.WebServiceContext; import jakarta.xml.ws.handler.MessageContext; import org.apache.cxf.systest.Book; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.jaxws.tracing.BookStoreService; @WebService(endpointInterface = "org.apache.cxf.systest.jaxws.tracing.BookStoreService", serviceName = "BookStore") @@ -45,7 +45,7 @@ public class BookStore implements BookStoreService { public BookStore() { brave = Tracing.newBuilder() .localServiceName("book-store") - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); } diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BraveTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BraveTracingTest.java index ab6a2af2942..e985f2f043f 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BraveTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/brave/BraveTracingTest.java @@ -22,7 +22,7 @@ import brave.Tracing; import org.apache.cxf.feature.Feature; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.brave.jaxws.AbstractBraveTracingTest; import org.apache.cxf.testutil.common.AbstractTestServerBase; import org.apache.cxf.tracing.brave.BraveClientFeature; @@ -44,7 +44,7 @@ public static class Server extends AbstractTestServerBase { protected void run() { final Tracing brave = Tracing.newBuilder() .localServiceName("book-store") - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); final JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(); @@ -68,7 +68,7 @@ public static void startServers() throws Exception { @After public void tearDown() { - TestSpanReporter.clear(); + TestSpanHandler.clear(); } @Override diff --git a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/micrometer/MicrometerTracingTest.java b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/micrometer/MicrometerTracingTest.java index a01121752c1..8996da34d7e 100644 --- a/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/micrometer/MicrometerTracingTest.java +++ b/systests/tracing/src/test/java/org/apache/cxf/systest/jaxws/tracing/micrometer/MicrometerTracingTest.java @@ -22,7 +22,7 @@ import org.apache.cxf.feature.Feature; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; import org.apache.cxf.message.Message; -import org.apache.cxf.systest.brave.TestSpanReporter; +import org.apache.cxf.systest.brave.TestSpanHandler; import org.apache.cxf.systest.brave.jaxws.AbstractBraveTracingTest; import org.apache.cxf.systest.jaxws.tracing.brave.BookStore; import org.apache.cxf.testutil.common.AbstractTestServerBase; @@ -57,7 +57,7 @@ public static class Server extends AbstractTestServerBase { protected void run() { final Tracing brave = Tracing.newBuilder() .localServiceName("book-store") - .spanReporter(new TestSpanReporter()) + .addSpanHandler(new TestSpanHandler()) .build(); final ObservationRegistry observationRegistry = createObservationRegistry(meterRegistry, brave); @@ -100,7 +100,7 @@ public static void startServers() throws Exception { @After public void tearDown() { - TestSpanReporter.clear(); + TestSpanHandler.clear(); } @Override