Skip to content

Commit 3c5ad72

Browse files
committed
add nullaway to spring
1 parent ae93a09 commit 3c5ad72

File tree

20 files changed

+65
-17
lines changed

20 files changed

+65
-17
lines changed

conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ nullaway {
1818

1919
tasks {
2020
withType<JavaCompile>().configureEach {
21-
options.errorprone.nullaway {
22-
if (name.contains("test", ignoreCase = true)) {
23-
disable()
24-
} else {
25-
error()
21+
options.errorprone {
22+
disable("RequireExplicitNullMarking") // is enabled by default is some spring projects
23+
24+
nullaway {
25+
if (name.contains("test", ignoreCase = true)) {
26+
disable()
27+
} else {
28+
error()
29+
}
30+
customInitializerAnnotations.add("org.openjdk.jmh.annotations.Setup")
31+
excludedFieldAnnotations.add("org.mockito.Mock")
32+
excludedFieldAnnotations.add("org.mockito.InjectMocks")
2633
}
27-
customInitializerAnnotations.add("org.openjdk.jmh.annotations.Setup")
28-
excludedFieldAnnotations.add("org.mockito.Mock")
29-
excludedFieldAnnotations.add("org.mockito.InjectMocks")
3034
}
3135
}
3236
}

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/http/HttpServerRoute.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ private HttpServerRoute() {}
5757
* strictly lower priority than the provided {@link HttpServerRouteSource}, and the passed value
5858
* is non-null.
5959
*/
60-
public static void update(Context context, HttpServerRouteSource source, String httpRoute) {
60+
public static void update(Context context, HttpServerRouteSource source,
61+
@Nullable String httpRoute) {
6162
update(context, source, ConstantAdapter.INSTANCE, httpRoute);
6263
}
6364

@@ -75,7 +76,7 @@ public static <T> void update(
7576
Context context,
7677
HttpServerRouteSource source,
7778
HttpServerRouteGetter<T> httpRouteGetter,
78-
T arg1) {
79+
@Nullable T arg1) {
7980
update(context, source, OneArgAdapter::get, arg1, httpRouteGetter);
8081
}
8182

instrumentation/spring/spring-webflux/spring-webflux-5.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-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/AdviceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static <T> Mono<T> wrapMono(Mono<T> mono, Context context) {
5050

5151
@FunctionalInterface
5252
interface OnSpanEnd {
53-
void end(Throwable throwable);
53+
void end(@Nullable Throwable throwable);
5454
}
5555

5656
private static class ContextMono<T> extends Mono<T> {

instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/RouteOnSuccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void accept(HandlerFunction<?> handler) {
3232
HttpServerRoute.update(Context.current(), HttpServerRouteSource.CONTROLLER, route);
3333
}
3434

35+
@Nullable
3536
private static String parsePredicateString(RouterFunction<?> routerFunction) {
3637
String routerFunctionString = routerFunction.toString();
3738
// Router functions containing lambda predicates should not end up in span tags since they are

instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSingletons.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static Instrumenter<Object, Void> instrumenter() {
3939

4040
public static HttpServerRouteGetter<ServerWebExchange> httpRouteGetter() {
4141
return (context, exchange) -> {
42+
if (exchange == null) {
43+
return null;
44+
}
4245
Object bestPatternObj = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
4346
if (bestPatternObj == null) {
4447
return null;

instrumentation/spring/spring-webmvc/spring-webmvc-3.1/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-webmvc/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/v3_1/SpringWebMvcServerSpanNaming.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class SpringWebMvcServerSpanNaming {
1414

1515
public static final HttpServerRouteGetter<HttpServletRequest> SERVER_SPAN_NAME =
1616
(context, request) -> {
17+
if (request == null) {
18+
return null;
19+
}
1720
Object bestMatchingPattern =
1821
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
1922
if (bestMatchingPattern != null) {

instrumentation/spring/spring-webmvc/spring-webmvc-5.3/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
val springBootVersion = "2.6.15"

instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/HttpRouteSupport.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ private void setHandlerMappings(List<HandlerMapping> mappings) {
9696
}
9797

9898
@Nullable
99-
String getHttpRoute(Context context, HttpServletRequest request) {
99+
String getHttpRoute(Context context, @Nullable HttpServletRequest request) {
100+
if (request == null) {
101+
return null;
102+
}
100103
boolean parsePath = this.parseRequestPath;
101104
Object previousValue = null;
102105
if (parsePath) {

0 commit comments

Comments
 (0)