Skip to content

Commit cc274cb

Browse files
authored
Merge pull request #195 from DataDog/tyler/npe
Defend against potential NPEs
2 parents 6e4f290 + f0d333c commit cc274cb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

dd-java-agent/instrumentation/spring-web/src/main/java/datadog/trace/instrumentation/springweb/SpringWebInstrumentation.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ public static class SpringWebAdvice {
5353
@Advice.OnMethodEnter(suppress = Throwable.class)
5454
public static void nameResource(@Advice.Argument(0) final HttpServletRequest request) {
5555
final Scope scope = GlobalTracer.get().scopeManager().active();
56-
if (scope != null) {
56+
if (scope != null && request != null) {
5757
final String method = request.getMethod();
58-
final String bestMatchingPattern =
59-
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString();
60-
final String resourceName = method + " " + bestMatchingPattern;
61-
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName);
58+
final Object bestMatchingPattern =
59+
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
60+
if (method != null && bestMatchingPattern != null) {
61+
final String resourceName = method + " " + bestMatchingPattern;
62+
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName);
63+
}
6264
}
6365
}
6466
}

0 commit comments

Comments
 (0)