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