Skip to content

Commit ec3f0c2

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 24942513837) (#18299)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent 5551b1f commit ec3f0c2

10 files changed

Lines changed: 29 additions & 31 deletions

File tree

instrumentation/apache-httpclient/apache-httpclient-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v2_0/ApacheHttpClientSingletons.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpClientInstrumenters;
1010
import org.apache.commons.httpclient.HttpMethod;
1111

12-
public class ApacheHttpClientSingletons {
12+
class ApacheHttpClientSingletons {
1313
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-2.0";
1414

1515
private static final Instrumenter<HttpMethod, HttpMethod> instrumenter;
@@ -22,7 +22,7 @@ public class ApacheHttpClientSingletons {
2222
new HttpHeaderSetter());
2323
}
2424

25-
public static Instrumenter<HttpMethod, HttpMethod> instrumenter() {
25+
static Instrumenter<HttpMethod, HttpMethod> instrumenter() {
2626
return instrumenter;
2727
}
2828

instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientInstrumentation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public ElementMatcher<TypeDescription> typeMatcher() {
4646
public void transform(TypeTransformer transformer) {
4747
// There are 8 execute(...) methods. Depending on the version, they may or may not delegate
4848
// to each other. Thus, all methods need to be instrumented. Because of argument position and
49-
// type, some methods can share the same advice class. The call depth tracking ensures only 1
50-
// span is created
49+
// type, some methods can share the same advice class. Span suppression ensures only one span
50+
// is created.
5151

5252
transformer.applyAdviceToMethod(
5353
named("execute")
@@ -161,6 +161,7 @@ public void end(@Nullable Object result, @Nullable Throwable throwable) {
161161
@SuppressWarnings("unused")
162162
public static class UriRequestAdvice {
163163

164+
@Nullable
164165
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
165166
public static AdviceScope methodEnter(@Advice.Argument(0) HttpUriRequest request) {
166167
return AdviceScope.start(new ApacheHttpClientRequest(request));
@@ -210,9 +211,10 @@ public static void methodExit(
210211
@SuppressWarnings("unused")
211212
public static class RequestAdvice {
212213

214+
@Nullable
213215
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
214216
public static AdviceScope methodEnter(
215-
@Advice.Argument(0) HttpHost host, @Advice.Argument(1) HttpRequest request) {
217+
@Advice.Argument(0) @Nullable HttpHost host, @Advice.Argument(1) HttpRequest request) {
216218
return AdviceScope.start(new ApacheHttpClientRequest(host, request));
217219
}
218220

@@ -234,7 +236,7 @@ public static class RequestWithHandlerAdvice {
234236
@AssignReturned.ToArguments(@ToArgument(value = 2, index = 1))
235237
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
236238
public static Object[] methodEnter(
237-
@Advice.Argument(0) HttpHost host,
239+
@Advice.Argument(0) @Nullable HttpHost host,
238240
@Advice.Argument(1) HttpRequest request,
239241
@Advice.Argument(2) ResponseHandler<?> handler) {
240242

instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientRequest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ApacheHttpClientRequest {
2929
private final HttpRequest delegate;
3030
@Nullable private final HttpHost target;
3131

32-
public ApacheHttpClientRequest(HttpHost httpHost, HttpRequest httpRequest) {
32+
public ApacheHttpClientRequest(@Nullable HttpHost httpHost, HttpRequest httpRequest) {
3333
URI calculatedUri = getUri(httpRequest);
3434
if (calculatedUri != null && httpHost != null) {
3535
uri = getCalculatedUri(httpHost, calculatedUri);
@@ -46,7 +46,7 @@ public ApacheHttpClientRequest(HttpUriRequest httpRequest) {
4646
target = null;
4747
}
4848

49-
public List<String> getHeader(String name) {
49+
List<String> getHeader(String name) {
5050
return headersToList(delegate.getHeaders(name));
5151
}
5252

@@ -62,16 +62,16 @@ static List<String> headersToList(Header[] headers) {
6262
return headersList;
6363
}
6464

65-
public void setHeader(String name, String value) {
65+
void setHeader(String name, String value) {
6666
delegate.setHeader(name, value);
6767
}
6868

69-
public String getMethod() {
69+
String getMethod() {
7070
return delegate.getRequestLine().getMethod();
7171
}
7272

7373
@Nullable
74-
public String getUrl() {
74+
String getUrl() {
7575
return uri != null ? uri.toString() : null;
7676
}
7777

@@ -88,7 +88,7 @@ String getProtocolVersion() {
8888
}
8989

9090
@Nullable
91-
public String getServerAddress() {
91+
String getServerAddress() {
9292
if (uri != null) {
9393
return uri.getHost();
9494
}
@@ -99,7 +99,7 @@ public String getServerAddress() {
9999
}
100100

101101
@Nullable
102-
public Integer getServerPort() {
102+
Integer getServerPort() {
103103
if (uri != null) {
104104
return uri.getPort();
105105
}
@@ -110,7 +110,7 @@ public Integer getServerPort() {
110110
}
111111

112112
@Nullable
113-
public String getScheme() {
113+
String getScheme() {
114114
if (uri != null) {
115115
return uri.getScheme();
116116
}

instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/WrappingStatusSettingResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import org.apache.http.HttpResponse;
1414
import org.apache.http.client.ResponseHandler;
1515

16-
public class WrappingStatusSettingResponseHandler<T> implements ResponseHandler<T> {
16+
class WrappingStatusSettingResponseHandler<T> implements ResponseHandler<T> {
1717
private final Context context;
1818
private final Context parentContext;
1919
private final ApacheHttpClientRequest request;
2020
private final ResponseHandler<T> handler;
2121

22-
public WrappingStatusSettingResponseHandler(
22+
WrappingStatusSettingResponseHandler(
2323
Context context,
2424
Context parentContext,
2525
ApacheHttpClientRequest request,

instrumentation/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v4_0/ApacheHttpClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public ClientConnectionManager newInstance(
7676
@Nested
7777
class ApacheClientHostRequestTest extends AbstractTest<BasicHttpRequest> {
7878
@Override
79-
public BasicHttpRequest createRequest(String method, URI uri) {
79+
BasicHttpRequest createRequest(String method, URI uri) {
8080
// also testing with an absolute path below
8181
return new BasicHttpRequest(method, fullPathFromUri(uri));
8282
}
8383

8484
@Override
85-
public HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception {
85+
HttpResponse doExecuteRequest(BasicHttpRequest request, URI uri) throws Exception {
8686
return getClient(uri).execute(getHost(uri), request);
8787
}
8888

instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientInstrumentation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public static Object[] methodEnter(
202202

203203
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
204204
public static void methodExit(
205-
@Advice.Argument(0) ClassicHttpRequest request,
206205
@Advice.Return @Nullable Object result,
207206
@Advice.Thrown @Nullable Throwable throwable,
208207
@Advice.Enter Object[] enterResult) {
@@ -238,7 +237,6 @@ public static Object[] methodEnter(
238237

239238
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
240239
public static void methodExit(
241-
@Advice.Argument(0) ClassicHttpRequest request,
242240
@Advice.Return @Nullable Object result,
243241
@Advice.Thrown @Nullable Throwable throwable,
244242
@Advice.Enter Object[] enterResult) {

instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/ApacheHttpClientSingletons.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.apache.hc.core5.http.HttpRequest;
1111
import org.apache.hc.core5.http.HttpResponse;
1212

13-
public class ApacheHttpClientSingletons {
13+
class ApacheHttpClientSingletons {
1414
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-5.0";
1515

1616
private static final Instrumenter<HttpRequest, HttpResponse> instrumenter;
@@ -23,7 +23,7 @@ public class ApacheHttpClientSingletons {
2323
new HttpHeaderSetter());
2424
}
2525

26-
public static Instrumenter<HttpRequest, HttpResponse> instrumenter() {
26+
static Instrumenter<HttpRequest, HttpResponse> instrumenter() {
2727
return instrumenter;
2828
}
2929

instrumentation/apache-httpclient/apache-httpclient-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachehttpclient/v5_0/WrappingStatusSettingResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import org.apache.hc.core5.http.HttpException;
1616
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
1717

18-
public class WrappingStatusSettingResponseHandler<T> implements HttpClientResponseHandler<T> {
18+
class WrappingStatusSettingResponseHandler<T> implements HttpClientResponseHandler<T> {
1919
private final Context context;
2020
private final Context parentContext;
2121
private final ClassicHttpRequest request;
2222
private final HttpClientResponseHandler<T> handler;
2323

24-
public WrappingStatusSettingResponseHandler(
24+
WrappingStatusSettingResponseHandler(
2525
Context context,
2626
Context parentContext,
2727
ClassicHttpRequest request,

instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/OtelExecChainHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ private ClassicHttpResponse execute(
7070
try (io.opentelemetry.context.Scope ignored = context.makeCurrent()) {
7171
response = chain.proceed(request, scope);
7272
return response;
73-
} catch (Exception e) {
74-
error = e;
75-
throw e;
73+
} catch (Throwable t) {
74+
error = t;
75+
throw t;
7676
} finally {
7777
instrumenter.end(context, instrumenterRequest, response, error);
7878
}

instrumentation/apache-shenyu-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apacheshenyu/v2_4/ContextBuilderInstrumentation.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.apacheshenyu.v2_4;
77

8+
import static io.opentelemetry.javaagent.instrumentation.apacheshenyu.v2_4.ApacheShenYuSingletons.httpRouteGetter;
89
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
910
import static net.bytebuddy.matcher.ElementMatchers.named;
1011
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -46,10 +47,7 @@ public static void onExit(@Advice.Argument(0) ServerWebExchange exchange) {
4647
return;
4748
}
4849
HttpServerRoute.update(
49-
context,
50-
HttpServerRouteSource.NESTED_CONTROLLER,
51-
ApacheShenYuSingletons.httpRouteGetter(),
52-
metaData);
50+
context, HttpServerRouteSource.NESTED_CONTROLLER, httpRouteGetter(), metaData);
5351
MetaDataHelper.extractAttributes(metaData, context);
5452
}
5553
}

0 commit comments

Comments
 (0)