Skip to content

Commit 1905166

Browse files
authored
Merge pull request #224 from DataDog/tyler/version-casing
Add exception for version segments in URLs
2 parents c84b4a2 + 9fc5cf6 commit 1905166

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

dd-trace-ot/src/main/java/datadog/opentracing/decorators/URLAsResourceName.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class URLAsResourceName extends AbstractDecorator {
1111

1212
// Matches everything after the ? character.
1313
public static final Pattern QUERYSTRING = Pattern.compile("\\?.*$");
14-
// Matches any path segments with numbers in them.
14+
// Matches any path segments with numbers in them. (exception for versioning: "/v1/")
1515
public static final Pattern PATH_MIXED_ALPHANUMERICS =
16-
Pattern.compile("/(?:[^\\/\\d\\?]*[\\d]+[^\\/\\?]*)");
16+
Pattern.compile("(?<=/)(?![vV]\\d{1,2}/)(?:[^\\/\\d\\?]*[\\d]+[^\\/\\?]*)");
1717

1818
public URLAsResourceName() {
1919
super();
@@ -60,7 +60,7 @@ private String norm(final String origin) {
6060

6161
String norm = origin;
6262
norm = QUERYSTRING.matcher(norm).replaceAll("");
63-
norm = PATH_MIXED_ALPHANUMERICS.matcher(norm).replaceAll("/?");
63+
norm = PATH_MIXED_ALPHANUMERICS.matcher(norm).replaceAll("?");
6464

6565
return norm;
6666
}

dd-trace-ot/src/test/groovy/datadog/opentracing/decorators/URLAsResourceNameTest.groovy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class URLAsResourceNameTest extends Specification {
2020

2121
where:
2222
input | output
23+
"/" | "/"
24+
"/?asdf" | "/"
2325
"/search" | "/search"
2426
"/search?" | "/search"
2527
"/search?id=100&private=true" | "/search"
@@ -52,10 +54,10 @@ class URLAsResourceNameTest extends Specification {
5254

5355
where:
5456
input | output
55-
"/a1" | "/?"
56-
"/1a" | "/?"
57-
"/abc/-1?" | "/abc/?"
58-
"/ABC/a-1/b_2/c.3/d4d/5f/6" | "/ABC/?/?/?/?/?/?"
57+
"/a1/v2" | "/?/?"
58+
"/v3/1a" | "/v3/?"
59+
"/V01/v9/abc/-1?" | "/V01/v9/abc/?"
60+
"/ABC/av-1/b_2/c.3/d4d/v5f/v699/7" | "/ABC/?/?/?/?/?/?/?"
5961
"/user/asdf123/repository/01234567-9ABC-DEF0-1234" | "/user/?/repository/?"
6062
}
6163

0 commit comments

Comments
 (0)