Better span names for servlet
MODIFY
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/filter/FilterInstrumentation.java
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/filter/FilterInstrumentation.java
@@ -25,7 +25,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
import io.opentelemetry.auto.instrumentation.api.SpanWithScope;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.trace.Span;
@@ -85,11 +84,10 @@ public final class FilterInstrumentation extends Instrumenter.Default {
return null;
}
- final Span span = TRACER.spanBuilder("servlet.filter").startSpan();
- DECORATE.afterStart(span);
-
// Here we use "this" instead of "the method target" to distinguish abstract filter instances.
- span.setAttribute(MoreTags.RESOURCE_NAME, filter.getClass().getSimpleName() + ".doFilter");
+ final Span span =
+ TRACER.spanBuilder(filter.getClass().getSimpleName() + ".doFilter").startSpan();
+ DECORATE.afterStart(span);
return new SpanWithScope(span, TRACER.withSpan(span));
}

MODIFY
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/http/HttpServletInstrumentation.java
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/http/HttpServletInstrumentation.java
@@ -27,7 +27,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
import io.opentelemetry.auto.instrumentation.api.SpanWithScope;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.trace.Span;
@@ -92,11 +91,9 @@ public final class HttpServletInstrumentation extends Instrumenter.Default {
return null;
}
- final Span span = TRACER.spanBuilder("servlet." + method.getName()).startSpan();
- DECORATE.afterStart(span);
-
// Here we use the Method instead of "this.class.name" to distinguish calls to "super".
- span.setAttribute(MoreTags.RESOURCE_NAME, DECORATE.spanNameForMethod(method));
+ final Span span = TRACER.spanBuilder(DECORATE.spanNameForMethod(method)).startSpan();
+ DECORATE.afterStart(span);
return new SpanWithScope(span, TRACER.withSpan(span));
}

MODIFY
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/http/HttpServletResponseInstrumentation.java
instrumentation/servlet/src/main/java/io/opentelemetry/auto/instrumentation/servlet/http/HttpServletResponseInstrumentation.java
@@ -24,7 +24,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService;
import io.opentelemetry.auto.bootstrap.InstrumentationContext;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
import io.opentelemetry.auto.instrumentation.api.SpanWithScope;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.trace.Span;
@@ -88,11 +87,9 @@ public final class HttpServletResponseInstrumentation extends Instrumenter.Defau
return null;
}
- final Span span = TRACER.spanBuilder("servlet.response").startSpan();
+ final Span span = TRACER.spanBuilder("HttpServletResponse." + method).startSpan();
DECORATE.afterStart(span);
- span.setAttribute(MoreTags.RESOURCE_NAME, "HttpServletResponse." + method);
-
return new SpanWithScope(span, TRACER.withSpan(span));
}

MODIFY
instrumentation/servlet/src/test/groovy/FilterTest.groovy
instrumentation/servlet/src/test/groovy/FilterTest.groovy
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
@@ -54,10 +53,9 @@ class FilterTest extends AgentTestRunner {
trace(0, 2) {
basicSpan(it, 0, "parent")
span(1) {
- operationName "servlet.filter"
+ operationName "${filter.class.simpleName}.doFilter"
childOf span(0)
tags {
- "$MoreTags.RESOURCE_NAME" "${filter.class.simpleName}.doFilter"
"$Tags.COMPONENT" "java-web-servlet-filter"
}
}
@@ -91,11 +89,10 @@ class FilterTest extends AgentTestRunner {
trace(0, 2) {
basicSpan(it, 0, "parent", null, null, ex)
span(1) {
- operationName "servlet.filter"
+ operationName "${filter.class.simpleName}.doFilter"
childOf span(0)
errored true
tags {
- "$MoreTags.RESOURCE_NAME" "${filter.class.simpleName}.doFilter"
"$Tags.COMPONENT" "java-web-servlet-filter"
errorTags(ex.class, ex.message)
}

MODIFY
instrumentation/servlet/src/test/groovy/HttpServletResponseTest.groovy
instrumentation/servlet/src/test/groovy/HttpServletResponseTest.groovy
* limitations under the License.
*/
import groovy.servlet.AbstractHttpServlet
-import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import spock.lang.Subject
@@ -72,26 +71,23 @@ class HttpServletResponseTest extends AgentTestRunner {
trace(0, 4) {
basicSpan(it, 0, "parent")
span(1) {
- operationName "servlet.response"
+ operationName "HttpServletResponse.sendError"
childOf span(0)
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServletResponse.sendError"
"$Tags.COMPONENT" "java-web-servlet-response"
}
}
span(2) {
- operationName "servlet.response"
+ operationName "HttpServletResponse.sendError"
childOf span(0)
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServletResponse.sendError"
"$Tags.COMPONENT" "java-web-servlet-response"
}
}
span(3) {
- operationName "servlet.response"
+ operationName "HttpServletResponse.sendRedirect"
childOf span(0)
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServletResponse.sendRedirect"
"$Tags.COMPONENT" "java-web-servlet-response"
}
}
@@ -127,11 +123,10 @@ class HttpServletResponseTest extends AgentTestRunner {
trace(0, 2) {
basicSpan(it, 0, "parent", null, null, ex)
span(1) {
- operationName "servlet.response"
+ operationName "HttpServletResponse.sendRedirect"
childOf span(0)
errored true
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServletResponse.sendRedirect"
"$Tags.COMPONENT" "java-web-servlet-response"
errorTags(ex.class, ex.message)
}

MODIFY
instrumentation/servlet/src/test/groovy/HttpServletTest.groovy
instrumentation/servlet/src/test/groovy/HttpServletTest.groovy
* limitations under the License.
*/
import groovy.servlet.AbstractHttpServlet
-import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
@@ -57,18 +56,16 @@ class HttpServletTest extends AgentTestRunner {
trace(0, 3) {
basicSpan(it, 0, "parent")
span(1) {
- operationName "servlet.service"
+ operationName "HttpServlet.service"
childOf span(0)
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServlet.service"
"$Tags.COMPONENT" "java-web-servlet-service"
}
}
span(2) {
- operationName "servlet.doGet"
+ operationName "${expectedResourceName}.doGet"
childOf span(1)
tags {
- "$MoreTags.RESOURCE_NAME" "${expectedResourceName}.doGet"
"$Tags.COMPONENT" "java-web-servlet-service"
}
}
@@ -108,21 +105,19 @@ class HttpServletTest extends AgentTestRunner {
trace(0, 3) {
basicSpan(it, 0, "parent", null, null, ex)
span(1) {
- operationName "servlet.service"
+ operationName "HttpServlet.service"
childOf span(0)
errored true
tags {
- "$MoreTags.RESOURCE_NAME" "HttpServlet.service"
"$Tags.COMPONENT" "java-web-servlet-service"
errorTags(ex.class, ex.message)
}
}
span(2) {
- operationName "servlet.doGet"
+ operationName "${servlet.class.name}.doGet"
childOf span(1)
errored true
tags {
- "$MoreTags.RESOURCE_NAME" "${servlet.class.name}.doGet"
"$Tags.COMPONENT" "java-web-servlet-service"
errorTags(ex.class, ex.message)
}

Better span names for servlet (#243)