Skip to content

Commit

Permalink
Fix consecutive slashes in derived path; remove HTTP method from span…
Browse files Browse the repository at this point in the history
… name to pass TCK tests that do not expect it
  • Loading branch information
tjquinno committed Jan 11, 2024
1 parent f70a6a7 commit fd55958
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,17 @@ private String spanName(ContainerRequestContext requestContext) {

Resource resource = extendedUriInfo.getMatchedModelResource();
while (resource != null) {
derivedPath.push(resource.getPath());
if (!resource.getPath().startsWith("/")) {
derivedPath.push("/");
String resourcePath = resource.getPath();
if (!resourcePath.equals("/") && !resourcePath.isBlank()) {
derivedPath.push(resourcePath);
if (!resourcePath.startsWith("/")) {
derivedPath.push("/");
}
}
resource = resource.getParent();
}

derivedPath.push(applicationPath());
derivedPath.push(requestContext.getMethod() + " ");
return String.join("", derivedPath);
}

Expand All @@ -193,7 +195,7 @@ private String applicationPath() {
return "";
}
ApplicationPath applicationPath = getRealClass(app.getClass()).getAnnotation(ApplicationPath.class);
return (applicationPath == null) ? "" : applicationPath.value();
return (applicationPath == null || applicationPath.value().equals("/")) ? "" : applicationPath.value();
}

// Resolve target string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testDefaultAppSpanNameFromPath(SpanPathTestInfo spanPathTestInfo) {
}

static Stream<SpanPathTestInfo> testDefaultAppSpanNameFromPath() {
return Stream.of(new SpanPathTestInfo("traced", "GET /traced"),
new SpanPathTestInfo("traced/sub/data", "GET /traced/sub/{name}"));
return Stream.of(new SpanPathTestInfo("traced", "/traced"),
new SpanPathTestInfo("traced/sub/data", "/traced/sub/{name}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void testExplicitAppSpanNameFromPath(SpanPathTestInfo spanPathTestInfo) {
}

static Stream<SpanPathTestInfo> testExplicitAppSpanNameFromPath() {
return Stream.of(new SpanPathTestInfo("topapp/apptraced", "GET /topapp/apptraced"),
new SpanPathTestInfo("topapp/apptraced/sub/data", "GET /topapp/apptraced/sub/{name}"));
return Stream.of(new SpanPathTestInfo("topapp/apptraced", "/topapp/apptraced"),
new SpanPathTestInfo("topapp/apptraced/sub/data", "/topapp/apptraced/sub/{name}"));
}
}

0 comments on commit fd55958

Please sign in to comment.