Add a few missing in instrumentation-api
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementSanitizer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementSanitizer.java
@@ -10,6 +10,7 @@ import static io.opentelemetry.instrumentation.api.internal.SupportabilityMetric
import io.opentelemetry.instrumentation.api.caching.Cache;
import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This class is responsible for masking potentially sensitive parameters in SQL (and SQL-like)
@@ -21,7 +22,7 @@ public final class SqlStatementSanitizer {
private static final Cache<String, SqlStatementInfo> sqlToStatementInfoCache =
Cache.newBuilder().setMaximumSize(1000).build();
- public static SqlStatementInfo sanitize(String statement) {
+ public static SqlStatementInfo sanitize(@Nullable String statement) {
if (!isStatementSanitizationEnabled() || statement == null) {
return SqlStatementInfo.create(statement, null, null);
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java
@@ -42,7 +42,8 @@ public abstract class AttributesExtractor<REQUEST, RESPONSE> {
* Sets the {@code value} with the given {@code key} to the {@link AttributesBuilder} if {@code
* value} is not {@code null}.
*/
- protected static <T> void set(AttributesBuilder attributes, AttributeKey<T> key, T value) {
+ protected static <T> void set(
+ AttributesBuilder attributes, AttributeKey<T> key, @Nullable T value) {
if (value != null) {
attributes.put(key, value);
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/EndTimeExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/EndTimeExtractor.java
package io.opentelemetry.instrumentation.api.instrumenter;
import java.time.Instant;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Extractor of the end time of response processing. An {@link EndTimeExtractor} should always use
@@ -16,5 +17,5 @@ import java.time.Instant;
public interface EndTimeExtractor<RESPONSE> {
/** Returns the timestamp marking the end of the response processing. */
- Instant extract(RESPONSE response);
+ Instant extract(@Nullable RESPONSE response);
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java
@@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.code;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.tracer.ClassNames;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A helper {@link SpanNameExtractor} implementation for instrumentations that target specific Java
@@ -37,7 +38,7 @@ public final class CodeSpanNameExtractor<REQUEST> implements SpanNameExtractor<R
return className + "." + methodName;
}
- private static String defaultString(String s) {
+ private static String defaultString(@Nullable String s) {
return s == null ? "<unknown>" : s;
}
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java
@@ -30,7 +30,8 @@ public abstract class RpcAttributesExtractor<REQUEST, RESPONSE>
}
@Override
- protected final void onEnd(AttributesBuilder attributes, REQUEST request, RESPONSE response) {
+ protected final void onEnd(
+ AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response) {
// No response attributes
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ContextPropagationDebug.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ContextPropagationDebug.java
@@ -12,6 +12,7 @@ import io.opentelemetry.instrumentation.api.config.Config;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,6 +69,7 @@ public final class ContextPropagationDebug {
}
}
+ @Nullable
private static List<Propagation> getPropagations(Context context) {
return context.get(THREAD_PROPAGATION_LOCATIONS);
}

Add a few missing @Nullables in instrumentation-api (#3806)