Span name should not have http method
MODIFY
instrumentation/spring-webflux-5.0/src/main/java8/io/opentelemetry/auto/instrumentation/springwebflux/server/HandlerAdapterAdvice.java
instrumentation/spring-webflux-5.0/src/main/java8/io/opentelemetry/auto/instrumentation/springwebflux/server/HandlerAdapterAdvice.java
@@ -59,8 +59,7 @@ public class HandlerAdapterAdvice {
final PathPattern bestPattern =
exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (parentSpan != null && bestPattern != null) {
- final String resourceName =
- exchange.getRequest().getMethodValue() + " " + bestPattern.getPatternString();
+ final String resourceName = bestPattern.getPatternString();
parentSpan.updateName(resourceName);
}

MODIFY
instrumentation/spring-webflux-5.0/src/main/java8/io/opentelemetry/auto/instrumentation/springwebflux/server/RouteOnSuccessOrError.java
instrumentation/spring-webflux-5.0/src/main/java8/io/opentelemetry/auto/instrumentation/springwebflux/server/RouteOnSuccessOrError.java
@@ -26,6 +26,8 @@ public class RouteOnSuccessOrError implements BiConsumer<HandlerFunction<?>, Thr
private static final Pattern SPECIAL_CHARACTERS_REGEX = Pattern.compile("[\\(\\)&|]");
private static final Pattern SPACES_REGEX = Pattern.compile("[ \\t]+");
+ private static final Pattern METHOD_REGEX =
+ Pattern.compile("^(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) ");
private final RouterFunction routerFunction;
private final ServerRequest serverRequest;
@@ -48,8 +50,7 @@ public class RouteOnSuccessOrError implements BiConsumer<HandlerFunction<?>, Thr
final Span parentSpan =
(Span) serverRequest.attributes().get(AdviceUtils.PARENT_SPAN_ATTRIBUTE);
if (parentSpan != null) {
- final String resourceName = parseResourceName(predicateString);
- parentSpan.updateName(resourceName);
+ parentSpan.updateName(parseRoute(predicateString));
}
}
}
@@ -67,10 +68,13 @@ public class RouteOnSuccessOrError implements BiConsumer<HandlerFunction<?>, Thr
}
}
- private String parseResourceName(final String routerString) {
- return SPACES_REGEX
+ private String parseRoute(final String routerString) {
+ return METHOD_REGEX
+ .matcher(
+ SPACES_REGEX
.matcher(SPECIAL_CHARACTERS_REGEX.matcher(routerString).replaceAll(""))
.replaceAll(" ")
- .trim();
+ .trim())
+ .replaceAll("");
}
}

MODIFY
instrumentation/spring-webflux-5.0/src/test/groovy/SpringWebfluxTest.groovy
instrumentation/spring-webflux-5.0/src/test/groovy/SpringWebfluxTest.groovy
@@ -67,7 +67,7 @@ class SpringWebfluxTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 2) {
span(0) {
- operationName "GET $urlPathWithVariables"
+ operationName urlPathWithVariables
spanKind SERVER
parent()
tags {
@@ -133,7 +133,7 @@ class SpringWebfluxTest extends AgentTestRunner {
println TEST_WRITER
trace(0, 3) {
span(0) {
- operationName "GET $urlPathWithVariables"
+ operationName urlPathWithVariables
spanKind SERVER
parent()
tags {
@@ -203,7 +203,7 @@ class SpringWebfluxTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 2) {
span(0) {
- operationName "GET /**"
+ operationName "/**"
spanKind SERVER
parent()
tags {
@@ -246,7 +246,7 @@ class SpringWebfluxTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 3) {
span(0) {
- operationName "POST /echo"
+ operationName "/echo"
spanKind SERVER
parent()
tags {
@@ -293,7 +293,7 @@ class SpringWebfluxTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 2) {
span(0) {
- operationName "GET $urlPathWithVariables"
+ operationName urlPathWithVariables
spanKind SERVER
errored true
parent()
@@ -359,7 +359,7 @@ class SpringWebfluxTest extends AgentTestRunner {
// TODO: why order of spans is different in these traces?
trace(0, 2) {
span(0) {
- operationName "GET /double-greet-redirect"
+ operationName "/double-greet-redirect"
spanKind SERVER
parent()
tags {
@@ -387,7 +387,7 @@ class SpringWebfluxTest extends AgentTestRunner {
}
trace(1, 2) {
span(0) {
- operationName "GET /double-greet"
+ operationName "/double-greet"
spanKind SERVER
parent()
tags {
@@ -430,7 +430,7 @@ class SpringWebfluxTest extends AgentTestRunner {
responses.eachWithIndex { def response, int i ->
trace(i, 2) {
span(0) {
- operationName "GET $urlPathWithVariables"
+ operationName urlPathWithVariables
spanKind SERVER
parent()
tags {

MODIFY
instrumentation/spring-webmvc-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springwebmvc/SpringWebHttpServerDecorator.java
instrumentation/spring-webmvc-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springwebmvc/SpringWebHttpServerDecorator.java
@@ -88,12 +88,10 @@ public class SpringWebHttpServerDecorator
@Override
public Span onRequest(final Span span, final HttpServletRequest request) {
if (request != null) {
- final String method = request.getMethod();
final Object bestMatchingPattern =
request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
- if (method != null && bestMatchingPattern != null) {
- final String resourceName = method + " " + bestMatchingPattern;
- span.updateName(resourceName);
+ if (bestMatchingPattern != null) {
+ span.updateName(bestMatchingPattern.toString());
}
}
return span;

MODIFY
instrumentation/spring-webmvc-3.1/src/test/groovy/test/SpringBootBasedTest.groovy
instrumentation/spring-webmvc-3.1/src/test/groovy/test/SpringBootBasedTest.groovy
@@ -109,7 +109,7 @@ class SpringBootBasedTest extends HttpServerTest<ConfigurableApplicationContext>
@Override
void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", ServerEndpoint endpoint = SUCCESS) {
trace.span(index) {
- operationName "$method ${endpoint == PATH_PARAM ? "/path/{id}/param" : endpoint.resolvePath(address).path}"
+ operationName endpoint == PATH_PARAM ? "/path/{id}/param" : endpoint.resolvePath(address).path
spanKind SERVER
errored endpoint.errored
if (parentID != null) {

MODIFY
smoke-tests/springboot/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy
smoke-tests/springboot/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy
@@ -20,7 +20,7 @@ import okhttp3.Request
class SpringBootSmokeTest extends AbstractServerSmokeTest {
static final HANDLER_SPAN = "LOGGED_SPAN WebController.greeting"
- static final SERVLET_SPAN = "LOGGED_SPAN GET /greeting"
+ static final SERVLET_SPAN = "LOGGED_SPAN /greeting"
@Override
ProcessBuilder createProcessBuilder() {

Span name should not have http method (#279)