diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java index 20eacf59e437..39a01b014c58 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java @@ -17,6 +17,7 @@ public class GrailsServerSpanNaming { info.getActionName() != null ? info.getActionName() : info.getControllerClass().getDefaultAction(); + // this is not the actual route/mapping, but it's the best thing that we have access to return ServletContextPath.prepend(context, "/" + info.getControllerName() + "/" + action); }; diff --git a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2Helper.java b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2Helper.java index 0aa698dc2823..43a7e0312201 100644 --- a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2Helper.java +++ b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2Helper.java @@ -5,12 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.axis2; -import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.axis2.Axis2Singletons.instrumenter; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import org.apache.axis2.jaxws.core.MessageContext; public final class Axis2Helper { @@ -24,8 +22,7 @@ public static void start(MessageContext message) { Context parentContext = Context.current(); Axis2Request request = new Axis2Request(message); - ServerSpanNaming.updateServerSpanName( - parentContext, CONTROLLER, Axis2ServerSpanNaming.SERVER_SPAN_NAME, request); + Axis2ServerSpanNaming.updateServerSpan(parentContext, request); if (!instrumenter().shouldStart(parentContext, request)) { return; diff --git a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2ServerSpanNaming.java b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2ServerSpanNaming.java index 44ca6850f4a5..000e8810bdc9 100644 --- a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2ServerSpanNaming.java +++ b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2ServerSpanNaming.java @@ -5,28 +5,34 @@ package io.opentelemetry.javaagent.instrumentation.axis2; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNameSupplier; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.tracer.ServerSpan; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.servlet.http.HttpServletRequest; import org.apache.axis2.jaxws.core.MessageContext; -public class Axis2ServerSpanNaming { +public final class Axis2ServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = - (context, axis2Request) -> { - String spanName = axis2Request.spanName(); - MessageContext message = axis2Request.message(); - HttpServletRequest request = - (HttpServletRequest) message.getMEPContext().get("transport.http.servletRequest"); - if (request != null) { - String servletPath = request.getServletPath(); - if (!servletPath.isEmpty()) { - spanName = servletPath + "/" + spanName; - } - } + public static void updateServerSpan(Context context, Axis2Request axis2Request) { + Span serverSpan = ServerSpan.fromContextOrNull(context); + if (serverSpan == null) { + return; + } - return ServletContextPath.prepend(context, spanName); - }; + String spanName = axis2Request.spanName(); + MessageContext message = axis2Request.message(); + HttpServletRequest request = + (HttpServletRequest) message.getMEPContext().get("transport.http.servletRequest"); + if (request != null) { + String servletPath = request.getServletPath(); + if (!servletPath.isEmpty()) { + spanName = servletPath + "/" + spanName; + } + } + + serverSpan.updateName(ServletContextPath.prepend(context, spanName)); + } private Axis2ServerSpanNaming() {} } diff --git a/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfHelper.java b/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfHelper.java index 9f6595f34b95..3b484d0b0642 100644 --- a/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfHelper.java +++ b/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfHelper.java @@ -5,12 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.cxf; -import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.cxf.CxfSingletons.instrumenter; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; @@ -31,8 +29,7 @@ public static void start(Message message) { return; } - ServerSpanNaming.updateServerSpanName( - parentContext, CONTROLLER, CxfServerSpanNaming.SERVER_SPAN_NAME, request); + CxfServerSpanNaming.updateServerSpanName(parentContext, request); if (!instrumenter().shouldStart(parentContext, request)) { return; diff --git a/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.java b/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.java index 2e5cc20d81ca..82944bf410ef 100644 --- a/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.java +++ b/instrumentation/jaxws/jaxws-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.java @@ -5,29 +5,35 @@ package io.opentelemetry.javaagent.instrumentation.cxf; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNameSupplier; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.tracer.ServerSpan; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.servlet.http.HttpServletRequest; -public class CxfServerSpanNaming { - - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = - (context, cxfRequest) -> { - String spanName = cxfRequest.spanName(); - if (spanName == null) { - return null; - } - - HttpServletRequest request = (HttpServletRequest) cxfRequest.message().get("HTTP.REQUEST"); - if (request != null) { - String servletPath = request.getServletPath(); - if (!servletPath.isEmpty()) { - spanName = servletPath + "/" + spanName; - } - } - - return ServletContextPath.prepend(context, spanName); - }; +public final class CxfServerSpanNaming { + + public static void updateServerSpanName(Context context, CxfRequest cxfRequest) { + String spanName = cxfRequest.spanName(); + if (spanName == null) { + return; + } + + Span serverSpan = ServerSpan.fromContextOrNull(context); + if (serverSpan == null) { + return; + } + + HttpServletRequest request = (HttpServletRequest) cxfRequest.message().get("HTTP.REQUEST"); + if (request != null) { + String servletPath = request.getServletPath(); + if (!servletPath.isEmpty()) { + spanName = servletPath + "/" + spanName; + } + } + + serverSpan.updateName(ServletContextPath.prepend(context, spanName)); + } private CxfServerSpanNaming() {} } diff --git a/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroHelper.java b/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroHelper.java index 49da206cbbc7..eaaf837ef34f 100644 --- a/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroHelper.java +++ b/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroHelper.java @@ -5,14 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.metro; -import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.metro.MetroSingletons.instrumenter; import com.sun.xml.ws.api.message.Packet; import com.sun.xml.ws.api.server.WSEndpoint; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; public final class MetroHelper { private static final String REQUEST_KEY = MetroHelper.class.getName() + ".Request"; @@ -26,8 +24,7 @@ public static void start(WSEndpoint endpoint, Packet packet) { Context parentContext = Context.current(); MetroRequest request = new MetroRequest(endpoint, packet); - ServerSpanNaming.updateServerSpanName( - parentContext, CONTROLLER, MetroServerSpanNaming.SERVER_SPAN_NAME, request); + MetroServerSpanNaming.updateServerSpanName(parentContext, request); if (!instrumenter().shouldStart(parentContext, request)) { return; diff --git a/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroServerSpanNaming.java b/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroServerSpanNaming.java index 6b625e64c844..742660249c9b 100644 --- a/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroServerSpanNaming.java +++ b/instrumentation/jaxws/jaxws-2.0-metro-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/metro/MetroServerSpanNaming.java @@ -6,40 +6,45 @@ package io.opentelemetry.javaagent.instrumentation.metro; import com.sun.xml.ws.api.message.Packet; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNameSupplier; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.tracer.ServerSpan; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.servlet.http.HttpServletRequest; import javax.xml.ws.handler.MessageContext; -public class MetroServerSpanNaming { +public final class MetroServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = - (context, metroRequest) -> { - String spanName = metroRequest.spanName(); - if (spanName == null) { - return null; - } + public static void updateServerSpanName(Context context, MetroRequest metroRequest) { + String spanName = metroRequest.spanName(); + if (spanName == null) { + return; + } + + Span serverSpan = ServerSpan.fromContextOrNull(context); + if (serverSpan == null) { + return; + } - Packet packet = metroRequest.packet(); - HttpServletRequest request = - (HttpServletRequest) packet.get(MessageContext.SERVLET_REQUEST); - if (request != null) { - String servletPath = request.getServletPath(); - if (!servletPath.isEmpty()) { - String pathInfo = request.getPathInfo(); - if (pathInfo != null) { - spanName = servletPath + "/" + spanName; - } else { - // when pathInfo is null then there is a servlet that is mapped to this exact service - // servletPath already contains the service name - String operationName = packet.getWSDLOperation().getLocalPart(); - spanName = servletPath + "/" + operationName; - } - } + Packet packet = metroRequest.packet(); + HttpServletRequest request = (HttpServletRequest) packet.get(MessageContext.SERVLET_REQUEST); + if (request != null) { + String servletPath = request.getServletPath(); + if (!servletPath.isEmpty()) { + String pathInfo = request.getPathInfo(); + if (pathInfo != null) { + spanName = servletPath + "/" + spanName; + } else { + // when pathInfo is null then there is a servlet that is mapped to this exact service + // servletPath already contains the service name + String operationName = packet.getWSDLOperation().getLocalPart(); + spanName = servletPath + "/" + operationName; } + } + } - return ServletContextPath.prepend(context, spanName); - }; + serverSpan.updateName(ServletContextPath.prepend(context, spanName)); + } private MetroServerSpanNaming() {} } diff --git a/instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/WebServiceProviderInstrumentation.java b/instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/WebServiceProviderInstrumentation.java index 311bd77f74b1..7771093546ae 100644 --- a/instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/WebServiceProviderInstrumentation.java +++ b/instrumentation/jaxws/jaxws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/WebServiceProviderInstrumentation.java @@ -5,7 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0; -import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; @@ -18,12 +17,10 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.CallDepth; import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsRequest; -import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsServerSpanNaming; import javax.xml.ws.Provider; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -66,8 +63,6 @@ public static void startSpan( Context parentContext = currentContext(); request = new JaxWsRequest(target.getClass(), methodName); - ServerSpanNaming.updateServerSpanName( - parentContext, CONTROLLER, JaxWsServerSpanNaming.SERVER_SPAN_NAME, request); if (!instrumenter().shouldStart(parentContext, request)) { return; } diff --git a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsServerSpanNaming.java b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsServerSpanNaming.java deleted file mode 100644 index a92d1805cccc..000000000000 --- a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsServerSpanNaming.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.jaxws.common; - -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNameSupplier; - -public class JaxWsServerSpanNaming { - - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = - (context, request) -> request.spanName(); - - private JaxWsServerSpanNaming() {} -} diff --git a/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsInstrumentation.java b/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsInstrumentation.java index 0e38d5cd30d6..683fdb038090 100644 --- a/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsInstrumentation.java +++ b/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsInstrumentation.java @@ -5,7 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1; -import static io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming.Source.CONTROLLER; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperMethod; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; @@ -20,12 +19,10 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.CallDepth; import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsRequest; -import io.opentelemetry.javaagent.instrumentation.jaxws.common.JaxWsServerSpanNaming; import javax.jws.WebService; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -77,8 +74,6 @@ public static void startSpan( Context parentContext = currentContext(); request = new JaxWsRequest(target.getClass(), methodName); - ServerSpanNaming.updateServerSpanName( - parentContext, CONTROLLER, JaxWsServerSpanNaming.SERVER_SPAN_NAME, request); if (!instrumenter().shouldStart(parentContext, request)) { return; } diff --git a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java index b13ddfef10d0..d9c99e8acb7d 100644 --- a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java +++ b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java @@ -50,7 +50,7 @@ public static void onExit(@Advice.Argument(0) IRequestHandler handler) { ServerSpanNaming.updateServerSpanName( context, CONTROLLER, - WicketServerSpanNameing.SERVER_SPAN_NAME, + WicketServerSpanNaming.SERVER_SPAN_NAME, (IPageClassRequestHandler) handler); } } diff --git a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNameing.java b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java similarity index 91% rename from instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNameing.java rename to instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java index 0d9914d41d90..66260718d4e8 100644 --- a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNameing.java +++ b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java @@ -10,7 +10,7 @@ import org.apache.wicket.core.request.handler.IPageClassRequestHandler; import org.apache.wicket.request.cycle.RequestCycle; -public class WicketServerSpanNameing { +public final class WicketServerSpanNaming { public static final ServerSpanNameSupplier SERVER_SPAN_NAME = (context, handler) -> { @@ -22,5 +22,5 @@ public class WicketServerSpanNameing { return ServletContextPath.prepend(context, filterPath + "/" + pageName); }; - private WicketServerSpanNameing() {} + private WicketServerSpanNaming() {} }