Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Mar 3, 2021
1 parent cca0203 commit 627b33d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Expand Up @@ -36,9 +36,8 @@ public static MappingResolver build(Collection<String> mappings) {
} else if (mapping.startsWith("*.") && mapping.length() > 2) {
wildcardMatchers.add(new SuffixMatcher("/" + mapping, mapping.substring(1)));
} else if (mapping.endsWith("/*")) {
exactMatches.add(mapping.substring(0, mapping.length() - 2));
wildcardMatchers.add(
new PrefixMatcher(mapping, mapping.substring(0, mapping.length() - 1)));
new PrefixMatcher(mapping, mapping.substring(0, mapping.length() - 2)));
} else {
exactMatches.add(mapping);
}
Expand Down Expand Up @@ -107,7 +106,7 @@ private PrefixMatcher(String mapping, String prefix) {

@Override
public boolean match(String path) {
return path.startsWith(prefix);
return path.equals(prefix) || path.startsWith(prefix + "/");
}

@Override
Expand Down
Expand Up @@ -45,7 +45,11 @@ private String getSpanName(
Object servletOrFilter, HttpServletRequest request, boolean allowNull) {
String spanName = getSpanName(servletOrFilter, request);
if (spanName == null && !allowNull) {
return "HTTP " + request.getMethod();
String contextPath = request.getContextPath();
if (contextPath == null || contextPath.isEmpty() || contextPath.equals("/")) {
return "HTTP " + request.getMethod();
}
return contextPath;
}
return spanName;
}
Expand Down
Expand Up @@ -67,8 +67,8 @@ abstract class AbstractServletMappingTest<SERVER, CONTEXT> extends AgentInstrume

where:
path | spanName | success
'prefix' | '/prefix' | true
'prefix/' | '/prefix' | true
'prefix' | '/prefix/*' | true
'prefix/' | '/prefix/*' | true
'prefix/a' | '/prefix/*' | true
'prefixa' | '/*' | false
'a.suffix' | '/*.suffix' | true
Expand Down

0 comments on commit 627b33d

Please sign in to comment.