Skip to content

Commit 3a9292f

Browse files
otelbot[bot]trask
andauthored
Code review sweep (run 25018389247) (open-telemetry#18346)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent e623d8d commit 3a9292f

11 files changed

Lines changed: 35 additions & 31 deletions

File tree

instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandInstrumentation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1919
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
20+
import javax.annotation.Nullable;
2021
import net.bytebuddy.asm.Advice;
2122
import net.bytebuddy.description.type.TypeDescription;
2223
import net.bytebuddy.matcher.ElementMatcher;
@@ -52,15 +53,18 @@ public static void saveContext(@Advice.This AsyncCommand<?, ?, ?> asyncCommand)
5253
public static class RestoreContextAdvice {
5354

5455
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
56+
@Nullable
5557
public static Scope onEnter(@Advice.This AsyncCommand<?, ?, ?> asyncCommand) {
5658

5759
Context context = CONTEXT.get(asyncCommand);
58-
return context.makeCurrent();
60+
return context == null ? null : context.makeCurrent();
5961
}
6062

6163
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
62-
public static void onExit(@Advice.Enter Scope scope) {
63-
scope.close();
64+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
65+
if (scope != null) {
66+
scope.close();
67+
}
6468
}
6569
}
6670
}

instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceFluxTerminationRunnable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ public class LettuceFluxTerminationRunnable implements Consumer<Signal<?>>, Runn
2525
DeclarativeConfigUtil.getInstrumentationConfig(GlobalOpenTelemetry.get(), "lettuce")
2626
.getBoolean("experimental_span_attributes/development", false);
2727

28+
private final FluxOnSubscribeConsumer onSubscribeConsumer;
2829
private Context context;
2930
private int numResults;
30-
private final FluxOnSubscribeConsumer onSubscribeConsumer;
3131

3232
public LettuceFluxTerminationRunnable(RedisCommand<?, ?, ?> command, boolean expectsResponse) {
3333
onSubscribeConsumer = new FluxOnSubscribeConsumer(this, command, expectsResponse);
3434
}
3535

36-
public FluxOnSubscribeConsumer getOnSubscribeConsumer() {
36+
public Consumer<Subscription> getOnSubscribeConsumer() {
3737
return onSubscribeConsumer;
3838
}
3939

instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceMonoDualConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
public class LettuceMonoDualConsumer<R, T> implements Consumer<R>, BiConsumer<T, Throwable> {
1818

19-
private Context context;
2019
private final RedisCommand<?, ?, ?> command;
2120
private final boolean finishSpanOnClose;
21+
private Context context;
2222

2323
public LettuceMonoDualConsumer(RedisCommand<?, ?, ?> command, boolean finishSpanOnClose) {
2424
this.command = command;

instrumentation/lettuce/lettuce-5.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/ClientResourcesInstrumentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
99
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
10+
import static io.opentelemetry.javaagent.instrumentation.lettuce.v5_1.TracingHolder.tracing;
1011
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
1112
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
1213
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -41,7 +42,7 @@ public static class BuilderAdvice {
4142
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
4243
public static void onExit(@Advice.Return ClientResources.Builder builder) {
4344
if (CompatibilityChecker.isCompatible()) {
44-
builder.tracing(TracingHolder.tracing());
45+
builder.tracing(tracing());
4546
}
4647
}
4748
}

instrumentation/lettuce/lettuce-5.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/CompatibilityChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private static boolean computeCompatibility() {
1515
try {
1616
Tracing.getContext();
1717
return true;
18-
} catch (Throwable t) {
18+
} catch (Throwable ignored) {
1919
return false;
2020
}
2121
}

instrumentation/lettuce/lettuce-5.1/testing/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.REDIS;
2525
import static org.assertj.core.api.Assertions.assertThat;
2626

27+
import io.lettuce.core.api.StatefulRedisConnection;
2728
import io.lettuce.core.api.sync.RedisCommands;
2829
import io.opentelemetry.api.trace.SpanKind;
2930
import java.lang.reflect.Method;
@@ -70,7 +71,9 @@ void testAuthCommand() throws ReflectiveOperationException {
7071
authMethod = commandsClass.getMethod("auth", CharSequence.class);
7172
}
7273

73-
String result = (String) authMethod.invoke(redisClient.connect().sync(), "password");
74+
StatefulRedisConnection<String, String> testConnection = redisClient.connect();
75+
cleanup.deferCleanup(testConnection);
76+
String result = (String) authMethod.invoke(testConnection.sync(), "password");
7477

7578
assertThat(result).isEqualTo("OK");
7679

instrumentation/liberty/liberty-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/v20_0/LibertyInstrumentationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* <li>On entry to WebApp.handleRequest remember request. {@link
2020
* LibertyWebAppInstrumentation.HandleRequestAdvice}
2121
* <li>On call to WebApp.isForbidden (called from WebApp.handleRequest) start span based on
22-
* remembered request. We don't start span immediately at the start or handleRequest because
22+
* remembered request. We don't start span immediately at the start of handleRequest because
2323
* HttpServletRequest isn't usable yet. {@link LibertyWebAppInstrumentation.IsForbiddenAdvice}
2424
* <li>On exit from WebApp.handleRequest close the span. {@link
2525
* LibertyWebAppInstrumentation.HandleRequestAdvice}

instrumentation/liberty/liberty-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/v20_0/ThreadLocalContext.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public void setScope(Scope scope) {
4545
this.scope = scope;
4646
}
4747

48-
public HttpServletRequest getRequest() {
49-
return requestContext.request();
50-
}
51-
5248
public ServletRequestContext<HttpServletRequest> getRequestContext() {
5349
return requestContext;
5450
}

instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LibertyDispatcherSingletons {
2121
new LibertyDispatcherRequestGetter());
2222
}
2323

24-
public static Instrumenter<LibertyRequest, LibertyResponse> instrumenter() {
24+
static Instrumenter<LibertyRequest, LibertyResponse> instrumenter() {
2525
return instrumenter;
2626
}
2727

instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyRequest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class LibertyRequest {
2121
@Nullable private final String clientSocketAddress;
2222
private final int clientSocketPort;
2323

24-
public LibertyRequest(
24+
LibertyRequest(
2525
HttpRequestMessage httpRequestMessage,
2626
@Nullable InetAddress serverInetAddress,
2727
int serverSocketPort,
@@ -36,33 +36,33 @@ public LibertyRequest(
3636
this.clientSocketPort = clientSocketPort;
3737
}
3838

39-
public String getMethod() {
39+
String getMethod() {
4040
return httpRequestMessage.getMethod();
4141
}
4242

43-
public String getScheme() {
43+
String getScheme() {
4444
return httpRequestMessage.getScheme();
4545
}
4646

47-
public String getRequestUri() {
47+
String getRequestUri() {
4848
return httpRequestMessage.getRequestURI();
4949
}
5050

51-
public String getQueryString() {
51+
String getQueryString() {
5252
return httpRequestMessage.getQueryString();
5353
}
5454

55-
public List<String> getAllHeaderNames() {
55+
List<String> getAllHeaderNames() {
5656
return httpRequestMessage.getAllHeaderNames();
5757
}
5858

5959
@Nullable
60-
public String getHeaderValue(String name) {
60+
String getHeaderValue(String name) {
6161
HeaderField hf = httpRequestMessage.getHeader(name);
6262
return hf != null ? hf.asString() : null;
6363
}
6464

65-
public List<String> getHeaderValues(String name) {
65+
List<String> getHeaderValues(String name) {
6666
List<HeaderField> headers = httpRequestMessage.getHeaders(name);
6767
if (headers.isEmpty()) {
6868
return emptyList();
@@ -74,25 +74,25 @@ public List<String> getHeaderValues(String name) {
7474
return stringHeaders;
7575
}
7676

77-
public String getProtocol() {
77+
String getProtocol() {
7878
return httpRequestMessage.getVersion();
7979
}
8080

8181
@Nullable
82-
public String getServerSocketAddress() {
82+
String getServerSocketAddress() {
8383
return serverSocketAddress;
8484
}
8585

86-
public int getServerSocketPort() {
86+
int getServerSocketPort() {
8787
return serverSocketPort;
8888
}
8989

9090
@Nullable
91-
public String getClientSocketAddress() {
91+
String getClientSocketAddress() {
9292
return clientSocketAddress;
9393
}
9494

95-
public int getClientSocketPort() {
95+
int getClientSocketPort() {
9696
return clientSocketPort;
9797
}
9898
}

0 commit comments

Comments
 (0)