Skip to content

Commit 2a84bcb

Browse files
committed
fix
1 parent a1a1145 commit 2a84bcb

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

instrumentation/ratpack/ratpack-1.4/testing/src/main/java/io/opentelemetry/instrumentation/ratpack/client/AbstractRatpackHttpClientTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ private static Throwable nettyClientSpanErrorMapper(URI uri, Throwable exception
182182
if (isWindows()) {
183183
return exception;
184184
}
185-
return rootCause != null ? rootCause : exception;
185+
Throwable candidate = rootCause != null ? rootCause : exception;
186+
Throwable timeoutCause = findExceptionWithMessage(exception, "connection timed out");
187+
if (timeoutCause != null) {
188+
candidate = timeoutCause;
189+
}
190+
return candidate;
186191
}
187192
return exception;
188193
}
@@ -222,4 +227,24 @@ private static Throwable unwrapConnectionException(Throwable exception) {
222227
}
223228
return current;
224229
}
230+
231+
private static Throwable findExceptionWithMessage(Throwable exception, String expectedFragment) {
232+
if (exception == null) {
233+
return null;
234+
}
235+
String needle = expectedFragment.toLowerCase(Locale.ROOT);
236+
Throwable current = exception;
237+
while (current != null) {
238+
String message = current.getMessage();
239+
if (message != null && message.toLowerCase(Locale.ROOT).contains(needle)) {
240+
return current;
241+
}
242+
Throwable cause = current.getCause();
243+
if (cause == null || cause == current) {
244+
break;
245+
}
246+
current = cause;
247+
}
248+
return null;
249+
}
225250
}

instrumentation/ratpack/ratpack-1.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/client/RatpackTestUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static Throwable ratpackClientSpanErrorMapper(URI uri, Throwable exceptio
2323
"Read timeout (PT2S) waiting on HTTP server at " + uri);
2424
}
2525
if (isNonRoutableAddress(uri) && exception instanceof ClosedChannelException) {
26+
if (OS.WINDOWS.isCurrentOs()) {
27+
return exception;
28+
}
2629
return new PrematureChannelClosureException();
2730
}
2831
return exception;

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,16 @@ private static Throwable nettyClientSpanErrorMapper(URI uri, Throwable exception
164164
return new HttpClientReadTimeoutException(
165165
"Read timeout (PT2S) waiting on HTTP server at " + uri);
166166
}
167-
if (!IS_WINDOWS && isNonRoutableAddress(uri) && exception instanceof ClosedChannelException) {
168-
return new PrematureChannelClosureException();
167+
if (isNonRoutableAddress(uri)) {
168+
if (exception instanceof ClosedChannelException) {
169+
return IS_WINDOWS ? exception : new PrematureChannelClosureException();
170+
}
171+
if (!IS_WINDOWS) {
172+
Throwable timeoutCause = findExceptionWithMessage(exception, "connection timed out");
173+
if (timeoutCause != null) {
174+
return timeoutCause;
175+
}
176+
}
169177
}
170178
return exception;
171179
}
@@ -202,4 +210,24 @@ private static boolean isNonRoutableAddress(URI uri) {
202210
private static boolean isUnopenedPort(URI uri) {
203211
return "localhost".equals(uri.getHost()) && uri.getPort() == PortUtils.UNUSABLE_PORT;
204212
}
213+
214+
private static Throwable findExceptionWithMessage(Throwable exception, String expectedFragment) {
215+
if (exception == null) {
216+
return null;
217+
}
218+
String needle = expectedFragment.toLowerCase(Locale.ROOT);
219+
Throwable current = exception;
220+
while (current != null) {
221+
String message = current.getMessage();
222+
if (message != null && message.toLowerCase(Locale.ROOT).contains(needle)) {
223+
return current;
224+
}
225+
Throwable cause = current.getCause();
226+
if (cause == null || cause == current) {
227+
break;
228+
}
229+
current = cause;
230+
}
231+
return null;
232+
}
205233
}

0 commit comments

Comments
 (0)