Skip to content

Commit a1a1145

Browse files
committed
fix
1 parent 9e3c130 commit a1a1145

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/OpenTelemetryHttpClient.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55

66
package io.opentelemetry.instrumentation.ratpack.v1_7.internal;
77

8-
import io.netty.handler.codec.PrematureChannelClosureException;
98
import io.opentelemetry.api.trace.Span;
109
import io.opentelemetry.context.Context;
1110
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1211
import io.opentelemetry.semconv.HttpAttributes;
13-
import java.net.ConnectException;
14-
import java.nio.channels.ClosedChannelException;
15-
import java.util.Locale;
1612
import ratpack.exec.Execution;
1713
import ratpack.http.client.HttpClient;
1814
import ratpack.http.client.HttpResponse;
@@ -72,38 +68,10 @@ public HttpClient instrument(HttpClient httpClient) throws Exception {
7268
.ifPresent(
7369
contextHolder -> {
7470
execution.remove(ContextHolder.class);
75-
RequestSpec requestSpec = contextHolder.requestSpec();
76-
Throwable error = mapClientError(requestSpec, ex);
77-
if (shouldRenameSpanToConnect(requestSpec, error)) {
78-
Span.fromContext(contextHolder.context()).updateName("CONNECT");
79-
}
80-
instrumenter.end(contextHolder.context(), requestSpec, null, error);
71+
instrumenter.end(
72+
contextHolder.context(), contextHolder.requestSpec(), null, ex);
8173
});
8274
});
8375
});
8476
}
85-
86-
private static Throwable mapClientError(RequestSpec requestSpec, Throwable error) {
87-
if (isNonRoutableAddress(requestSpec) && error instanceof ClosedChannelException) {
88-
return new PrematureChannelClosureException();
89-
}
90-
return error;
91-
}
92-
93-
private static boolean shouldRenameSpanToConnect(RequestSpec requestSpec, Throwable error) {
94-
if (error instanceof ConnectException) {
95-
return true;
96-
}
97-
return !isWindows()
98-
&& isNonRoutableAddress(requestSpec)
99-
&& error instanceof ClosedChannelException;
100-
}
101-
102-
private static boolean isNonRoutableAddress(RequestSpec requestSpec) {
103-
return "192.0.2.1".equals(requestSpec.getUri().getHost());
104-
}
105-
106-
private static boolean isWindows() {
107-
return System.getProperty("os.name", "").toLowerCase(Locale.ROOT).contains("win");
108-
}
10977
}

instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/AbstractRatpackHttpClientTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838

3939
abstract class AbstractRatpackHttpClientTest extends AbstractHttpClientTest<Void> {
4040

41+
private static final boolean IS_WINDOWS =
42+
System.getProperty("os.name", "").toLowerCase(Locale.ROOT).contains("win");
43+
4144
final ExecHarness exec = ExecHarness.harness();
4245

4346
HttpClient client;
@@ -161,21 +164,24 @@ private static Throwable nettyClientSpanErrorMapper(URI uri, Throwable exception
161164
return new HttpClientReadTimeoutException(
162165
"Read timeout (PT2S) waiting on HTTP server at " + uri);
163166
}
164-
if (isNonRoutableAddress(uri) && exception instanceof ClosedChannelException) {
167+
if (!IS_WINDOWS && isNonRoutableAddress(uri) && exception instanceof ClosedChannelException) {
165168
return new PrematureChannelClosureException();
166169
}
167170
return exception;
168171
}
169172

170173
private static String nettyExpectedClientSpanNameMapper(URI uri, String method) {
171174
if (isUnopenedPort(uri)) {
175+
if (IS_WINDOWS) {
176+
return HttpClientTestOptions.DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER.apply(uri, method);
177+
}
172178
return "CONNECT";
173179
}
174180
if (isNonRoutableAddress(uri)) {
175181
// On Windows, non-routable addresses don't fail at CONNECT level.
176182
// The connection proceeds far enough to start HTTP processing before
177183
// the channel closes, resulting in an HTTP span instead of CONNECT.
178-
if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")) {
184+
if (IS_WINDOWS) {
179185
return HttpClientTestOptions.DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER.apply(uri, method);
180186
}
181187
return "CONNECT";

0 commit comments

Comments
 (0)