Skip to content

Commit 284668a

Browse files
zeitlingerotelbot[bot]jaydelucatrask
authored
add nullaway to spring, part 3 (#15417)
Co-authored-by: otelbot <[email protected]> Co-authored-by: Jay DeLuca <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
1 parent d14d383 commit 284668a

File tree

18 files changed

+43
-12
lines changed

18 files changed

+43
-12
lines changed

instrumentation/kafka/kafka-clients/kafka-clients-common-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/common/v0_11/internal/KafkaProcessRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.kafkaclients.common.v0_11.internal;
77

8+
import javax.annotation.Nullable;
89
import org.apache.kafka.clients.consumer.Consumer;
910
import org.apache.kafka.clients.consumer.ConsumerRecord;
1011

@@ -16,7 +17,8 @@ public class KafkaProcessRequest extends AbstractKafkaConsumerRequest {
1617

1718
private final ConsumerRecord<?, ?> record;
1819

19-
public static KafkaProcessRequest create(ConsumerRecord<?, ?> record, Consumer<?, ?> consumer) {
20+
public static KafkaProcessRequest create(
21+
ConsumerRecord<?, ?> record, @Nullable Consumer<?, ?> consumer) {
2022
return create(record, KafkaUtil.getConsumerGroup(consumer), KafkaUtil.getClientId(consumer));
2123
}
2224

instrumentation/spring/spring-kafka-2.7/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.javaagent-instrumentation")
3+
id("otel.nullaway-conventions")
34
}
45

56
muzzle {

instrumentation/spring/spring-kafka-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/kafka/v2_7/ListenerConsumerInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void exit(@Nullable Throwable throwable) {
112112
}
113113

114114
@Advice.OnMethodEnter(suppress = Throwable.class)
115+
@Nullable
115116
public static AdviceScope onEnter(
116117
@Advice.Argument(0) ConsumerRecords<?, ?> records,
117118
@Advice.FieldValue("consumer") Consumer<?, ?> consumer) {

instrumentation/spring/spring-kafka-2.7/library/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.library-instrumentation")
3+
id("otel.nullaway-conventions")
34
}
45

56
dependencies {

instrumentation/spring/spring-kafka-2.7/library/src/main/java/io/opentelemetry/instrumentation/spring/kafka/v2_7/InstrumentedRecordInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ConsumerRecord<K, V> intercept(ConsumerRecord<K, V> record, Consumer<K, V
4848
return decorated == null ? record : decorated.intercept(record, consumer);
4949
}
5050

51-
private void start(ConsumerRecord<K, V> record, Consumer<K, V> consumer) {
51+
private void start(ConsumerRecord<K, V> record, @Nullable Consumer<K, V> consumer) {
5252
Context parentContext = getParentContext(record);
5353

5454
KafkaProcessRequest request = KafkaProcessRequest.create(record, consumer);

instrumentation/spring/spring-pulsar-1.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.javaagent-instrumentation")
3+
id("otel.nullaway-conventions")
34
}
45

56
muzzle {

instrumentation/spring/spring-rabbit-1.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.javaagent-instrumentation")
3+
id("otel.nullaway-conventions")
34
}
45

56
muzzle {

instrumentation/spring/spring-rabbit-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/rabbit/v1_0/MessageHeaderGetter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public Iterable<String> keys(Message carrier) {
1919

2020
@Nullable
2121
@Override
22-
public String get(Message carrier, String key) {
22+
public String get(@Nullable Message carrier, String key) {
23+
if (carrier == null) {
24+
return null;
25+
}
2326
Object value = carrier.getMessageProperties().getHeaders().get(key);
2427
return value == null ? null : value.toString();
2528
}

instrumentation/spring/spring-rmi-4.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("otel.javaagent-instrumentation")
3+
id("otel.nullaway-conventions")
34
}
45

56
muzzle {

instrumentation/spring/spring-rmi-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/rmi/v4_0/server/ServerInstrumentation.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.javaagent.bootstrap.rmi.ThreadLocalContext.THREAD_LOCAL_CONTEXT;
99
import static io.opentelemetry.javaagent.instrumentation.spring.rmi.v4_0.SpringRmiSingletons.serverInstrumenter;
10+
import static java.util.Objects.requireNonNull;
1011
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
1112
import static net.bytebuddy.matcher.ElementMatchers.named;
1213
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -45,12 +46,15 @@ public static class InvokeMethodAdvice {
4546

4647
public static class AdviceScope {
4748
private final CallDepth callDepth;
48-
private final ClassAndMethod request;
49-
private final Context context;
50-
private final Scope scope;
49+
@Nullable private final ClassAndMethod request;
50+
@Nullable private final Context context;
51+
@Nullable private final Scope scope;
5152

5253
private AdviceScope(
53-
CallDepth callDepth, ClassAndMethod request, Context context, Scope scope) {
54+
CallDepth callDepth,
55+
@Nullable ClassAndMethod request,
56+
@Nullable Context context,
57+
@Nullable Scope scope) {
5458
this.callDepth = callDepth;
5559
this.request = request;
5660
this.context = context;
@@ -81,7 +85,8 @@ public void exit(@Nullable Throwable throwable) {
8185
return;
8286
}
8387
scope.close();
84-
serverInstrumenter().end(context, request, null, throwable);
88+
// scope non-null implies context and request are both non-null (see enter method above)
89+
serverInstrumenter().end(requireNonNull(context), requireNonNull(request), null, throwable);
8590
}
8691
}
8792

0 commit comments

Comments
 (0)