Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExecInitializer #9

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.zipkin.brave.ratpack</groupId>
<artifactId>brave-ratpack</artifactId>
<version>2.3.3-SNAPSHOT</version>
<version>2.4.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>brave-ratpack</name>
<description>Brave instrumentation for Ratpack</description>
Expand Down Expand Up @@ -50,7 +50,7 @@
<license-maven-plugin.version>3.0</license-maven-plugin.version>

<brave.version>5.1.5</brave.version>
<ratpack.version>1.4.6</ratpack.version>
<ratpack.version>1.6.0</ratpack.version>

</properties>

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/ratpack/zipkin/ServerTracingModule.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -59,6 +56,9 @@ protected void configure() {

bind(ZipkinHttpClientImpl.class);

bind(RatpackCurrentTraceContext.TracingPropagationExecInitializer.class)
.in(Singleton.class);

Provider<ServerTracingHandler> serverTracingHandlerProvider =
getProvider(ServerTracingHandler.class);

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/ratpack/zipkin/TracedParallelBatch.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <T> the type of value produced by each promise in the batch.
*/
@Deprecated
public final class TracedParallelBatch<T> {

private final Iterable<? extends Promise<T>> promises;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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));
}
});
});
}
}

}
75 changes: 70 additions & 5 deletions src/main/java/ratpack/zipkin/internal/ZipkinHttpClientImpl.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -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<ReceivedResponse> request(URI uri, Action<? super RequestSpec> action) {
// save off the current span as the parent of a future client span
Expand Down Expand Up @@ -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) {

Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down