Skip to content

Commit

Permalink
Remove a few ServerSpanNaming usages (#4900)
Browse files Browse the repository at this point in the history
* Remove a few ServerSpanNaming usages

* revert vaadin changes
  • Loading branch information
Mateusz Rzeszutek authored Dec 21, 2021
1 parent 2531b6e commit 9e3bd5c
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Axis2Request> 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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CxfRequest> 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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetroRequest> 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() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPageClassRequestHandler> SERVER_SPAN_NAME =
(context, handler) -> {
Expand All @@ -22,5 +22,5 @@ public class WicketServerSpanNameing {
return ServletContextPath.prepend(context, filterPath + "/" + pageName);
};

private WicketServerSpanNameing() {}
private WicketServerSpanNaming() {}
}

0 comments on commit 9e3bd5c

Please sign in to comment.