Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

import javax.annotation.Nullable;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;

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

private final ConsumerRecord<?, ?> record;

public static KafkaProcessRequest create(ConsumerRecord<?, ?> record, Consumer<?, ?> consumer) {
public static KafkaProcessRequest create(
ConsumerRecord<?, ?> record, @Nullable Consumer<?, ?> consumer) {
return create(record, KafkaUtil.getConsumerGroup(consumer), KafkaUtil.getClientId(consumer));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void exit(@Nullable Throwable throwable) {
}

@Advice.OnMethodEnter(suppress = Throwable.class)
@Nullable
public static AdviceScope onEnter(
@Advice.Argument(0) ConsumerRecords<?, ?> records,
@Advice.FieldValue("consumer") Consumer<?, ?> consumer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ConsumerRecord<K, V> intercept(ConsumerRecord<K, V> record, Consumer<K, V
return decorated == null ? record : decorated.intercept(record, consumer);
}

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

KafkaProcessRequest request = KafkaProcessRequest.create(record, consumer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public Iterable<String> keys(Message carrier) {

@Nullable
@Override
public String get(Message carrier, String key) {
public String get(@Nullable Message carrier, String key) {
if (carrier == null) {
return null;
}
Object value = carrier.getMessageProperties().getHeaders().get(key);
return value == null ? null : value.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.javaagent.bootstrap.rmi.ThreadLocalContext.THREAD_LOCAL_CONTEXT;
import static io.opentelemetry.javaagent.instrumentation.spring.rmi.v4_0.SpringRmiSingletons.serverInstrumenter;
import static java.util.Objects.requireNonNull;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
Expand Down Expand Up @@ -45,12 +46,15 @@ public static class InvokeMethodAdvice {

public static class AdviceScope {
private final CallDepth callDepth;
private final ClassAndMethod request;
private final Context context;
private final Scope scope;
@Nullable private final ClassAndMethod request;
@Nullable private final Context context;
@Nullable private final Scope scope;

private AdviceScope(
CallDepth callDepth, ClassAndMethod request, Context context, Scope scope) {
CallDepth callDepth,
@Nullable ClassAndMethod request,
@Nullable Context context,
@Nullable Scope scope) {
this.callDepth = callDepth;
this.request = request;
this.context = context;
Expand Down Expand Up @@ -81,7 +85,8 @@ public void exit(@Nullable Throwable throwable) {
return;
}
scope.close();
serverInstrumenter().end(context, request, null, throwable);
// scope non-null implies context and request are both non-null (see enter method above)
serverInstrumenter().end(requireNonNull(context), requireNonNull(request), null, throwable);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
plugins {
id("otel.javaagent-bootstrap")
id("otel.nullaway-conventions")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter;
import java.lang.reflect.Field;
import javax.annotation.Nullable;
import org.springframework.scheduling.support.ScheduledMethodRunnable;

public class SpringSchedulingCodeAttributesGetter implements CodeAttributesGetter<Runnable> {
@Nullable
private static final Class<?> outcomeTrackingRunnableClass = getOutcomeTrackingRunnableClass();

@Nullable
private static final Field outcomeTrackingRunnableField =
getOutcomeTrackingRunnableField(outcomeTrackingRunnableClass);

@Nullable
private static Class<?> getOutcomeTrackingRunnableClass() {
try {
return Class.forName("org.springframework.scheduling.config.Task$OutcomeTrackingRunnable");
Expand All @@ -22,7 +27,11 @@ private static Class<?> getOutcomeTrackingRunnableClass() {
}
}

private static Field getOutcomeTrackingRunnableField(Class<?> clazz) {
@Nullable
private static Field getOutcomeTrackingRunnableField(@Nullable Class<?> clazz) {
if (clazz == null) {
return null;
}
try {
Field field = clazz.getDeclaredField("runnable");
field.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class TaskContextHolder implements ImplicitContextKeyed {
private static final ContextKey<TaskContextHolder> KEY =
named("opentelemetry-spring-scheduling-task");

private Context taskContext;
@Nullable private Context taskContext;

private TaskContextHolder() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.javaagent-instrumentation")
id("otel.nullaway-conventions")
}

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static EnduserAttributesCapturer createEndUserAttributesCapturerFromConf
.getString(
"otel.instrumentation.spring-security.enduser.scope.granted-authority-prefix");
if (scopePrefix != null) {
capturer.setScopeGrantedAuthorityPrefix(rolePrefix);
capturer.setScopeGrantedAuthorityPrefix(scopePrefix);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncovered a bug here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jup - pretty sure that's the case

}
return capturer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("otel.library-instrumentation")
id("otel.nullaway-conventions")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import java.util.Objects;
import javax.annotation.Nullable;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

Expand Down Expand Up @@ -97,8 +98,9 @@ public void captureEnduserAttributes(Context otelContext, Authentication authent
}
}

@Nullable
private static StringBuilder appendSuffix(
String prefix, String authorityString, StringBuilder builder) {
String prefix, String authorityString, @Nullable StringBuilder builder) {
if (authorityString.length() > prefix.length()) {
String suffix = authorityString.substring(prefix.length());
if (builder == null) {
Expand Down
Loading