diff --git a/pom.xml b/pom.xml
index da8991f..b4b9e2c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
4.0.0
io.zipkin.brave.ratpack
brave-ratpack
- 2.3.3-SNAPSHOT
+ 2.4.0-SNAPSHOT
jar
brave-ratpack
Brave instrumentation for Ratpack
@@ -50,7 +50,7 @@
3.0
5.1.5
- 1.4.6
+ 1.6.0
diff --git a/src/main/java/ratpack/zipkin/ServerTracingModule.java b/src/main/java/ratpack/zipkin/ServerTracingModule.java
index 5e7941b..2e956db 100644
--- a/src/main/java/ratpack/zipkin/ServerTracingModule.java
+++ b/src/main/java/ratpack/zipkin/ServerTracingModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 The OpenZipkin Authors
+ * Copyright 2016-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -33,10 +33,7 @@
import ratpack.handling.HandlerDecorator;
import ratpack.http.client.HttpClient;
import ratpack.server.ServerConfig;
-import ratpack.zipkin.internal.DefaultServerTracingHandler;
-import ratpack.zipkin.internal.RatpackCurrentTraceContext;
-import ratpack.zipkin.internal.RatpackHttpServerParser;
-import ratpack.zipkin.internal.ZipkinHttpClientImpl;
+import ratpack.zipkin.internal.*;
import zipkin2.Endpoint;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
@@ -59,6 +56,9 @@ protected void configure() {
bind(ZipkinHttpClientImpl.class);
+ bind(RatpackCurrentTraceContext.TracingPropagationExecInitializer.class)
+ .in(Singleton.class);
+
Provider serverTracingHandlerProvider =
getProvider(ServerTracingHandler.class);
diff --git a/src/main/java/ratpack/zipkin/TracedParallelBatch.java b/src/main/java/ratpack/zipkin/TracedParallelBatch.java
index c837455..e9b16ee 100644
--- a/src/main/java/ratpack/zipkin/TracedParallelBatch.java
+++ b/src/main/java/ratpack/zipkin/TracedParallelBatch.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 The OpenZipkin Authors
+ * Copyright 2016-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -27,8 +27,13 @@
* which do not "inherit" registries from the calling execution. Consequently,
* the trace context must be passed explicitly to the forked executions.
*
+ * @deprecated As of 2.4 brave-ratpack is now providing an {@link ratpack.exec.ExecInitializer} bound in guice by {@link ServerTracingModule}
+ * which will deal with passing tracing contexts around Ratpack executions. The propagation is done in {@link ratpack.zipkin.internal.RatpackCurrentTraceContext.TracingPropagationExecInitializer},
+ * this kind of propagation is only possible with Ratpack version 1.6 and above as the parent execution is now avaialble.
+ *
* @param the type of value produced by each promise in the batch.
*/
+@Deprecated
public final class TracedParallelBatch {
private final Iterable extends Promise> promises;
diff --git a/src/main/java/ratpack/zipkin/internal/RatpackCurrentTraceContext.java b/src/main/java/ratpack/zipkin/internal/RatpackCurrentTraceContext.java
index 44501a3..f48b788 100644
--- a/src/main/java/ratpack/zipkin/internal/RatpackCurrentTraceContext.java
+++ b/src/main/java/ratpack/zipkin/internal/RatpackCurrentTraceContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 The OpenZipkin Authors
+ * Copyright 2016-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -13,10 +13,12 @@
*/
package ratpack.zipkin.internal;
+import brave.http.HttpTracing;
import brave.propagation.CurrentTraceContext;
import brave.propagation.TraceContext;
import java.util.function.Supplier;
import org.slf4j.MDC;
+import ratpack.exec.ExecInitializer;
import ratpack.exec.Execution;
import ratpack.registry.MutableRegistry;
@@ -90,4 +92,24 @@ private TraceContextHolder(final TraceContext context) {
}
}
+ /**
+ * ExecInitializer that will propagate the tracing context into any new execution created.
+ */
+ public static class TracingPropagationExecInitializer implements ExecInitializer {
+
+ @Override
+ public void init(Execution execution) {
+ execution.maybeParent().ifPresent(parent -> {
+ parent.maybeGet(HttpTracing.class).ifPresent(httpTracing -> {
+ TraceContext traceContext = httpTracing.tracing().currentTraceContext().get();
+ if (traceContext == null) {
+ execution.add(RatpackCurrentTraceContext.TraceContextHolder.EMPTY);
+ } else {
+ execution.add(new RatpackCurrentTraceContext.TraceContextHolder(traceContext));
+ }
+ });
+ });
+ }
+ }
+
}
diff --git a/src/main/java/ratpack/zipkin/internal/ZipkinHttpClientImpl.java b/src/main/java/ratpack/zipkin/internal/ZipkinHttpClientImpl.java
index 6db2b86..793b1f5 100644
--- a/src/main/java/ratpack/zipkin/internal/ZipkinHttpClientImpl.java
+++ b/src/main/java/ratpack/zipkin/internal/ZipkinHttpClientImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 The OpenZipkin Authors
+ * Copyright 2016-2019 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -31,16 +31,15 @@
import java.util.function.BiFunction;
import javax.inject.Inject;
import javax.net.ssl.SSLContext;
+
+import io.netty.handler.ssl.SslContext;
import ratpack.exec.Promise;
import ratpack.exec.Result;
import ratpack.func.Action;
import ratpack.func.Function;
import ratpack.http.HttpMethod;
import ratpack.http.MutableHeaders;
-import ratpack.http.client.HttpClient;
-import ratpack.http.client.ReceivedResponse;
-import ratpack.http.client.RequestSpec;
-import ratpack.http.client.StreamedResponse;
+import ratpack.http.client.*;
/**
* Decorator that adds Zipkin client logging around {@link HttpClient}.
@@ -74,21 +73,41 @@ public int getPoolSize() {
return delegate.getPoolSize();
}
+ @Override
+ public int getPoolQueueSize() {
+ return delegate.getPoolQueueSize();
+ }
+
@Override
public Duration getReadTimeout() {
return delegate.getReadTimeout();
}
+ @Override
+ public Duration getConnectTimeout() {
+ return delegate.getConnectTimeout();
+ }
+
@Override
public int getMaxContentLength() {
return delegate.getMaxContentLength();
}
+ @Override
+ public int getMaxResponseChunkSize() {
+ return delegate.getMaxResponseChunkSize();
+ }
+
@Override
public void close() {
delegate.close();
}
+ @Override
+ public HttpClient copyWith(Action super HttpClientSpec> action) throws Exception {
+ return delegate.copyWith(action);
+ }
+
@Override
public Promise request(URI uri, Action super RequestSpec> action) {
// save off the current span as the parent of a future client span
@@ -222,6 +241,11 @@ public RequestSpec redirects(int maxRedirects) {
return this;
}
+ @Override
+ public int getRedirects() {
+ return delegate.getRedirects();
+ }
+
@Override
public RequestSpec onRedirect(Function super ReceivedResponse, Action super RequestSpec>> function) {
@@ -238,6 +262,16 @@ public RequestSpec sslContext(SSLContext sslContext) {
return this;
}
+ @Override
+ public SslContext getSslContext() {
+ return delegate.getSslContext();
+ }
+
+ @Override
+ public RequestSpec sslContext(SslContext sslContext) {
+ return delegate.sslContext(sslContext);
+ }
+
@Override
public MutableHeaders getHeaders() {
return this.delegate.getHeaders();
@@ -249,6 +283,17 @@ public RequestSpec maxContentLength(int numBytes) {
return this;
}
+ @Override
+ public int getMaxContentLength() {
+ return delegate.getMaxContentLength();
+ }
+
+ @Override
+ public RequestSpec responseMaxChunkSize(int i) {
+ this.delegate.responseMaxChunkSize(i);
+ return this;
+ }
+
@Override
public RequestSpec headers(Action super MutableHeaders> action) throws Exception {
this.delegate.headers(action);
@@ -264,12 +309,22 @@ public RequestSpec method(HttpMethod method) {
return this;
}
+ @Override
+ public HttpMethod getMethod() {
+ return delegate.getMethod();
+ }
+
@Override
public RequestSpec decompressResponse(boolean shouldDecompress) {
this.delegate.decompressResponse(shouldDecompress);
return this;
}
+ @Override
+ public boolean getDecompressResponse() {
+ return delegate.getDecompressResponse();
+ }
+
@Override
public URI getUri() {
return this.delegate.getUri();
@@ -281,12 +336,22 @@ public RequestSpec connectTimeout(Duration duration) {
return this;
}
+ @Override
+ public Duration getConnectTimeout() {
+ return delegate.getConnectTimeout();
+ }
+
@Override
public RequestSpec readTimeout(Duration duration) {
this.delegate.readTimeout(duration);
return this;
}
+ @Override
+ public Duration getReadTimeout() {
+ return delegate.getReadTimeout();
+ }
+
@Override
public Body getBody() {
return this.delegate.getBody();