Remove deprecated ServerSpanNaming.updateServerSpanName method
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/servlet/ServerSpanNaming.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/servlet/ServerSpanNaming.java
@@ -9,7 +9,6 @@ import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.instrumentation.api.tracer.ServerSpan;
-import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.Nullable;
/** Helper container for tracking whether instrumentation should update server span name or not. */
@@ -18,11 +17,6 @@ public final class ServerSpanNaming {
private static final ContextKey<ServerSpanNaming> CONTEXT_KEY =
ContextKey.named("opentelemetry-servlet-span-naming-key");
- // this is just to support deprecated methods
- @Deprecated
- private static final ServerSpanNameSupplier<Supplier<String>> ZERO_ARG_ADAPTER =
- (context, supplier) -> supplier.get();
-
public static Context init(Context context, Source initialSource) {
ServerSpanNaming serverSpanNaming = context.get(CONTEXT_KEY);
if (serverSpanNaming != null) {
@@ -108,12 +102,6 @@ public final class ServerSpanNaming {
}
}
- @Deprecated
- public static void updateServerSpanName(
- Context context, Source source, Supplier<String> serverSpanName) {
- updateServerSpanName(context, source, ZERO_ARG_ADAPTER, serverSpanName);
- }
-
// TODO (trask) migrate the one usage (ServletHttpServerTracer) to ServerSpanNaming.init() once we
// migrate to new Instrumenters (see
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/2814#discussion_r617351334

MODIFY
instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java
instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java
@@ -79,11 +79,12 @@ public abstract class BaseServletHelper<REQUEST, RESPONSE> {
public Context updateContext(
Context context, REQUEST request, MappingResolver mappingResolver, boolean servlet) {
+ Context result = addServletContextPath(context, request);
+ if (mappingResolver != null) {
ServerSpanNaming.updateServerSpanName(
- context,
- servlet ? SERVLET : FILTER,
- () -> spanNameProvider.getSpanNameOrNull(mappingResolver, request));
- return addServletContextPath(context, request);
+ result, servlet ? SERVLET : FILTER, spanNameProvider, mappingResolver, request);
+ }
+ return result;
}
/*

MODIFY
instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/naming/ServletSpanNameProvider.java
instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/naming/ServletSpanNameProvider.java
package io.opentelemetry.instrumentation.servlet.naming;
+import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.servlet.MappingResolver;
+import io.opentelemetry.instrumentation.api.servlet.ServerSpanNameTwoArgSupplier;
+import io.opentelemetry.instrumentation.api.servlet.ServletContextPath;
import io.opentelemetry.instrumentation.servlet.ServletAccessor;
+import org.checkerframework.checker.nullness.qual.Nullable;
/** Helper class for constructing span name for given servlet/filter mapping and request. */
-public class ServletSpanNameProvider<REQUEST> {
+public class ServletSpanNameProvider<REQUEST>
+ implements ServerSpanNameTwoArgSupplier<MappingResolver, REQUEST> {
private final ServletAccessor<REQUEST, ?> servletAccessor;
public ServletSpanNameProvider(ServletAccessor<REQUEST, ?> servletAccessor) {
this.servletAccessor = servletAccessor;
}
- public String getSpanName(MappingResolver mappingResolver, REQUEST request) {
- String spanName = getSpanNameOrNull(mappingResolver, request);
- if (spanName == null) {
- String contextPath = servletAccessor.getRequestContextPath(request);
- if (contextPath == null || contextPath.isEmpty() || contextPath.equals("/")) {
- return "HTTP " + servletAccessor.getRequestMethod(request);
- }
- return contextPath + "/*";
- }
- return spanName;
- }
-
- public String getSpanNameOrNull(MappingResolver mappingResolver, REQUEST request) {
- if (mappingResolver == null) {
- return null;
- }
-
+ @Override
+ public @Nullable String get(Context context, MappingResolver mappingResolver, REQUEST request) {
String servletPath = servletAccessor.getRequestServletPath(request);
String pathInfo = servletAccessor.getRequestPathInfo(request);
String mapping = mappingResolver.resolve(servletPath, pathInfo);
@@ -41,11 +31,6 @@ public class ServletSpanNameProvider<REQUEST> {
return null;
}
- // prepend context path
- String contextPath = servletAccessor.getRequestContextPath(request);
- if (contextPath == null || contextPath.isEmpty() || contextPath.equals("/")) {
- return mapping;
- }
- return contextPath + mapping;
+ return ServletContextPath.prepend(context, mapping);
}
}

Remove deprecated ServerSpanNaming.updateServerSpanName method (#4318)