|
5 | 5 |
|
6 | 6 | package io.opentelemetry.instrumentation.ratpack.v1_7.internal; |
7 | 7 |
|
8 | | -import io.netty.handler.codec.PrematureChannelClosureException; |
9 | 8 | import io.opentelemetry.api.trace.Span; |
10 | 9 | import io.opentelemetry.context.Context; |
11 | 10 | import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; |
12 | 11 | import io.opentelemetry.semconv.HttpAttributes; |
13 | | -import java.net.ConnectException; |
14 | | -import java.nio.channels.ClosedChannelException; |
15 | | -import java.util.Locale; |
16 | 12 | import ratpack.exec.Execution; |
17 | 13 | import ratpack.http.client.HttpClient; |
18 | 14 | import ratpack.http.client.HttpResponse; |
@@ -72,38 +68,10 @@ public HttpClient instrument(HttpClient httpClient) throws Exception { |
72 | 68 | .ifPresent( |
73 | 69 | contextHolder -> { |
74 | 70 | 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); |
81 | 73 | }); |
82 | 74 | }); |
83 | 75 | }); |
84 | 76 | } |
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 | | - } |
109 | 77 | } |
0 commit comments