Merge pull request #195 from DataDog/tyler/npe

Defend against potential NPEs
This commit is contained in:
Tyler Benson 2018-01-19 16:04:37 -05:00 committed by GitHub
commit cc274cb3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -53,12 +53,14 @@ public final class SpringWebInstrumentation implements Instrumenter {
@Advice.OnMethodEnter(suppress = Throwable.class) @Advice.OnMethodEnter(suppress = Throwable.class)
public static void nameResource(@Advice.Argument(0) final HttpServletRequest request) { public static void nameResource(@Advice.Argument(0) final HttpServletRequest request) {
final Scope scope = GlobalTracer.get().scopeManager().active(); final Scope scope = GlobalTracer.get().scopeManager().active();
if (scope != null) { if (scope != null && request != null) {
final String method = request.getMethod(); final String method = request.getMethod();
final String bestMatchingPattern = final Object bestMatchingPattern =
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString(); request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
final String resourceName = method + " " + bestMatchingPattern; if (method != null && bestMatchingPattern != null) {
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName); final String resourceName = method + " " + bestMatchingPattern;
scope.span().setTag(DDTags.RESOURCE_NAME, resourceName);
}
} }
} }
} }