From 942f0ff794412c3eeb10930c30d5ad165482d8ef Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 13:25:23 -0700 Subject: [PATCH 1/8] spanNameForMethod --- .../api/tracer/BaseTracer.java | 35 ------------------- .../api/tracer/HttpServerTracer.java | 2 +- .../ExternalAnnotationTracer.java | 3 +- .../jaxrs/v1_0/JaxRsAnnotationsTracer.java | 3 +- .../jaxrs/v2_0/JaxRsAnnotationsTracer.java | 3 +- .../jaxws/common/JaxWsTracer.java | 3 +- .../otelannotations/WithSpanTracer.java | 5 +-- .../servlet/v5_0/response/ResponseTracer.java | 3 +- .../javax/response/ResponseTracer.java | 3 +- .../spring/data/SpringDataTracer.java | 3 +- .../scheduling/SpringSchedulingTracer.java | 3 +- .../spring/ws/SpringWsTracer.java | 3 +- .../struts2/Struts2Tracer.java | 3 +- .../instrumentation/vaadin/VaadinTracer.java | 9 ++--- 14 files changed, 29 insertions(+), 52 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java index 6479590769e7..d6ca8e16fb48 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java @@ -21,12 +21,10 @@ import io.opentelemetry.instrumentation.api.internal.ContextPropagationDebug; import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import org.checkerframework.checker.nullness.qual.Nullable; /** * Base class for all instrumentation specific tracer implementations. @@ -178,39 +176,6 @@ protected final Context withServerSpan(Context parentContext, Span span) { return ServerSpan.with(parentContext.with(span), span); } - /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. - * - * @deprecated Use {@link SpanNames#spanNameForMethod(Method)}. - */ - @Deprecated - public static String spanNameForMethod(Method method) { - return SpanNames.spanNameForMethod(method); - } - - /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. - * - * @deprecated Use {@link SpanNames#spanNameForMethod(Class, Method)}. - */ - @Deprecated - public static String spanNameForMethod(Class clazz, @Nullable Method method) { - return SpanNames.spanNameForMethod(clazz, method); - } - - /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. - * - * @deprecated Use {@link SpanNames#spanNameForMethod(Class, String)}. - */ - @Deprecated - public static String spanNameForMethod(Class cl, String methodName) { - return SpanNames.spanNameForMethod(cl, methodName); - } - /** * This method is used to generate an acceptable span (operation) name based on a given class * reference. Anonymous classes are named based on their parent. diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java index 9f67f067f94a..00239955b099 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java @@ -48,7 +48,7 @@ protected HttpServerTracer(OpenTelemetry openTelemetry) { } public Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin) { - String spanName = spanNameForMethod(origin); + String spanName = SpanNames.spanNameForMethod(origin); return startSpan(request, connection, storage, spanName); } diff --git a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java index f8d65513462c..1958ee00a92e 100644 --- a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java +++ b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java @@ -7,6 +7,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; public class ExternalAnnotationTracer extends BaseTracer { @@ -22,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(spanNameForMethod(method)); + return startSpan(SpanNames.spanNameForMethod(method)); } } diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java index e11c0992482e..b776eab6f45b 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java @@ -12,6 +12,7 @@ import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.api.tracer.ServerSpan; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.javaagent.instrumentation.api.ClassHierarchyIterable; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.lang.annotation.Annotation; @@ -47,7 +48,7 @@ public Context startSpan(Class target, Method method) { if (serverSpan == null) { spanName = pathBasedSpanName; } else { - spanName = spanNameForMethod(target, method); + spanName = SpanNames.spanNameForMethod(target, method); updateServerSpanName(parentContext, serverSpan, pathBasedSpanName); } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java index 6d10d20f03de..32b26ff228fc 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java @@ -14,6 +14,7 @@ import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.api.tracer.ServerSpan; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.javaagent.instrumentation.api.ClassHierarchyIterable; import io.opentelemetry.javaagent.instrumentation.api.jaxrs.JaxrsContextPath; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -69,7 +70,7 @@ public void updateSpanNames( } else { ServerSpanNaming.updateServerSpanName( context, ServerSpanNaming.Source.CONTROLLER, spanNameSupplier); - updateSpanName(span, spanNameForMethod(target, method)); + updateSpanName(span, SpanNames.spanNameForMethod(target, method)); } } diff --git a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java index dee04f385a78..f39b78cb848c 100644 --- a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java +++ b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java @@ -11,6 +11,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.api.tracer.ServerSpan; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.lang.reflect.Method; @@ -28,7 +29,7 @@ protected String getInstrumentationName() { } public Context startSpan(Class target, Method method) { - String spanName = spanNameForMethod(target, method); + String spanName = SpanNames.spanNameForMethod(target, method); Context parentContext = Context.current(); Span serverSpan = ServerSpan.fromContextOrNull(parentContext); diff --git a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java index c9cc21934f0c..1fc38c21f6ab 100644 --- a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java +++ b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.instrumentation.api.tracer.async.AsyncSpanEndStrategies; import io.opentelemetry.instrumentation.api.tracer.async.AsyncSpanEndStrategy; import java.lang.reflect.Method; @@ -47,13 +48,13 @@ parentContext, spanNameForMethodWithAnnotation(applicationAnnotation, method), k * This method is used to generate an acceptable span (operation) name based on a given method * reference. It first checks for existence of {@link WithSpan} annotation. If it is present, then * tries to derive name from its {@code value} attribute. Otherwise delegates to {@link - * #spanNameForMethod(Method)}. + * SpanNames#spanNameForMethod(Method)}. */ public String spanNameForMethodWithAnnotation(WithSpan applicationAnnotation, Method method) { if (applicationAnnotation != null && !applicationAnnotation.value().isEmpty()) { return applicationAnnotation.value(); } - return spanNameForMethod(method); + return SpanNames.spanNameForMethod(method); } public SpanKind extractSpanKind(WithSpan applicationAnnotation) { diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java index 7f99d25ec4cc..f3cc52e8ece2 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java @@ -7,6 +7,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; public class ResponseTracer extends BaseTracer { @@ -22,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(spanNameForMethod(method)); + return startSpan(SpanNames.spanNameForMethod(method)); } } diff --git a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java index 4be66f2338f1..875bf6e4def8 100644 --- a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java @@ -7,6 +7,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; public class ResponseTracer extends BaseTracer { @@ -22,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(spanNameForMethod(method)); + return startSpan(SpanNames.spanNameForMethod(method)); } } diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java index 507f48fe97e3..c48dd8a85641 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java @@ -7,6 +7,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; public final class SpringDataTracer extends BaseTracer { @@ -24,6 +25,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(spanNameForMethod(method)); + return startSpan(SpanNames.spanNameForMethod(method)); } } diff --git a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java index 2f25f9c53530..f5acd6768eac 100644 --- a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java +++ b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import org.springframework.scheduling.support.ScheduledMethodRunnable; public class SpringSchedulingTracer extends BaseTracer { @@ -29,7 +30,7 @@ public Context startSpan(Runnable runnable) { private static String spanNameOnRun(Runnable runnable) { if (runnable instanceof ScheduledMethodRunnable) { ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable; - return spanNameForMethod(scheduledMethodRunnable.getMethod()); + return SpanNames.spanNameForMethod(scheduledMethodRunnable.getMethod()); } else { return spanNameForClass(runnable.getClass()) + "/run"; } diff --git a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java index 81d1575abf19..f212d8f5d54c 100644 --- a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java +++ b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.lang.reflect.Method; @@ -23,7 +24,7 @@ public static SpringWsTracer tracer() { public Context startSpan(Method method) { Context parentContext = Context.current(); Span span = - spanBuilder(parentContext, spanNameForMethod(method), SpanKind.INTERNAL) + spanBuilder(parentContext, SpanNames.spanNameForMethod(method), SpanKind.INTERNAL) .setAttribute(SemanticAttributes.CODE_NAMESPACE, method.getDeclaringClass().getName()) .setAttribute(SemanticAttributes.CODE_FUNCTION, method.getName()) .startSpan(); diff --git a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java index cdb8db766ae1..694452d03c75 100644 --- a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java +++ b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java @@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; public class Struts2Tracer extends BaseTracer { @@ -30,7 +31,7 @@ public Context startSpan(Context parentContext, ActionInvocation actionInvocatio Class actionClass = action.getClass(); String method = actionInvocation.getProxy().getMethod(); - String spanName = spanNameForMethod(actionClass, method); + String spanName = SpanNames.spanNameForMethod(actionClass, method); SpanBuilder strutsSpan = spanBuilder(parentContext, spanName, INTERNAL); diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java index 584adb7fd478..22320512d0e5 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java @@ -18,6 +18,7 @@ import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.api.tracer.ServerSpan; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; import org.checkerframework.checker.nullness.qual.Nullable; @@ -38,7 +39,7 @@ private VaadinTracer() { } public Context startVaadinServiceSpan(VaadinService vaadinService, Method method) { - String spanName = spanNameForMethod(vaadinService.getClass(), method); + String spanName = SpanNames.spanNameForMethod(vaadinService.getClass(), method); Context context = super.startSpan(spanName); return context.with(SERVICE_CONTEXT_KEY, new VaadinServiceContext(spanName)); } @@ -75,7 +76,7 @@ public Context startRequestHandlerSpan(RequestHandler requestHandler, Method met return null; } - String spanName = spanNameForMethod(requestHandler.getClass(), method); + String spanName = SpanNames.spanNameForMethod(requestHandler.getClass(), method); VaadinServiceContext vaadinServiceContext = current.get(SERVICE_CONTEXT_KEY); if (vaadinServiceContext != null && !vaadinServiceContext.isRequestHandled()) { Span span = ServerSpan.fromContextOrNull(current); @@ -125,12 +126,12 @@ public void updateServerSpanName(Location location) { } public Context startClientCallableSpan(Class componentClass, String methodName) { - return super.startSpan(spanNameForMethod(componentClass, methodName)); + return super.startSpan(SpanNames.spanNameForMethod(componentClass, methodName)); } public Context startRpcInvocationHandlerSpan( RpcInvocationHandler rpcInvocationHandler, Method method, JsonObject jsonObject) { - String spanName = spanNameForMethod(rpcInvocationHandler.getClass(), method); + String spanName = SpanNames.spanNameForMethod(rpcInvocationHandler.getClass(), method); if ("event".equals(rpcInvocationHandler.getRpcType())) { String eventType = jsonObject.getString("event"); if (eventType != null) { From fe82c3cb58da56ea192bf875292b52c281eef557 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 13:27:35 -0700 Subject: [PATCH 2/8] spanNameForClass --- .../instrumentation/api/tracer/BaseTracer.java | 11 ----------- .../instrumentation/finatra/FinatraTracer.java | 3 ++- .../instrumentation/grails/GrailsTracer.java | 3 ++- .../rediscala/RediscalaClientTracer.java | 3 ++- .../spring/scheduling/SpringSchedulingTracer.java | 2 +- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java index d6ca8e16fb48..b3b19e760906 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java @@ -176,17 +176,6 @@ protected final Context withServerSpan(Context parentContext, Span span) { return ServerSpan.with(parentContext.with(span), span); } - /** - * This method is used to generate an acceptable span (operation) name based on a given class - * reference. Anonymous classes are named based on their parent. - * - * @deprecated Use {@link SpanNames#spanNameForClass(Class)}. - */ - @Deprecated - public static String spanNameForClass(Class clazz) { - return SpanNames.spanNameForClass(clazz); - } - /** Ends the execution of a span stored in the passed {@code context}. */ public void end(Context context) { end(context, -1); diff --git a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java index 5314ee447a93..afcfd80d283e 100644 --- a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java +++ b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; public class FinatraTracer extends BaseTracer { private static final FinatraTracer TRACER = new FinatraTracer(); @@ -22,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Context parentContext, Class clazz) { - return super.startSpan(parentContext, spanNameForClass(clazz), SpanKind.INTERNAL); + return super.startSpan(parentContext, SpanNames.spanNameForClass(clazz), SpanKind.INTERNAL); } } diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java index eb7d72660b37..b4096928dacc 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.servlet.ServerSpanNaming; import io.opentelemetry.instrumentation.api.servlet.ServletContextPath; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import org.grails.web.mapping.mvc.GrailsControllerUrlMappingInfo; public class GrailsTracer extends BaseTracer { @@ -22,7 +23,7 @@ public static GrailsTracer tracer() { } public Context startSpan(Object controller, String action) { - return startSpan(spanNameForClass(controller.getClass()) + "." + action); + return startSpan(SpanNames.spanNameForClass(controller.getClass()) + "." + action); } public void updateServerSpanName(Context context, GrailsControllerUrlMappingInfo info) { diff --git a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java index 81d81ce3e5ad..2689bd8bdc20 100644 --- a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java +++ b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.rediscala; import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DbSystemValues; import java.net.InetSocketAddress; @@ -26,7 +27,7 @@ public static RediscalaClientTracer tracer() { @Override protected String sanitizeStatement(RedisCommand redisCommand) { - return spanNameForClass(redisCommand.getClass()); + return SpanNames.spanNameForClass(redisCommand.getClass()); } @Override diff --git a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java index f5acd6768eac..207f184871fc 100644 --- a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java +++ b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java @@ -32,7 +32,7 @@ private static String spanNameOnRun(Runnable runnable) { ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable; return SpanNames.spanNameForMethod(scheduledMethodRunnable.getMethod()); } else { - return spanNameForClass(runnable.getClass()) + "/run"; + return SpanNames.spanNameForClass(runnable.getClass()) + "/run"; } } } From 311df870ac7b2305c3df0d0141a031a21701a59f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 13:47:12 -0700 Subject: [PATCH 3/8] no static import --- .../springwebmvc/HandlerSpanNameExtractor.java | 5 ++--- .../springwebmvc/ModelAndViewAttributesExtractor.java | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java index 0584248bb1d9..1d2fd79c7e1c 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java @@ -5,9 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc; -import static io.opentelemetry.instrumentation.api.tracer.SpanNames.spanNameForMethod; - import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import java.lang.reflect.Method; import javax.servlet.Servlet; import org.springframework.web.HttpRequestHandler; @@ -43,6 +42,6 @@ public String extract(Object handler) { methodName = ""; } - return spanNameForMethod(clazz, methodName); + return SpanNames.spanNameForMethod(clazz, methodName); } } diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java index 6ed738e26bc6..5285652b6765 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java @@ -5,11 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc; -import static io.opentelemetry.instrumentation.api.tracer.SpanNames.spanNameForClass; - import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.tracer.SpanNames; import org.checkerframework.checker.nullness.qual.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; @@ -27,7 +26,7 @@ protected void onStart(AttributesBuilder attributes, ModelAndView modelAndView) attributes.put("spring-webmvc.view.name", modelAndView.getViewName()); View view = modelAndView.getView(); if (view != null) { - attributes.put("spring-webmvc.view.type", spanNameForClass(view.getClass())); + attributes.put("spring-webmvc.view.type", SpanNames.spanNameForClass(view.getClass())); } } } From a3530c9f64b508cef203bf96ea2672c681695264 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 13:56:17 -0700 Subject: [PATCH 4/8] Renames --- .../code/CodeSpanNameExtractor.java | 4 +- .../api/tracer/ClassNames.java | 27 ++++++++++++ .../api/tracer/HttpServerTracer.java | 2 +- .../instrumentation/api/tracer/SpanNames.java | 42 ++++++------------- .../api/tracer/SpanNamesTest.groovy | 37 ++++++++++------ .../ExternalAnnotationTracer.java | 2 +- .../finatra/FinatraTracer.java | 4 +- .../instrumentation/grails/GrailsTracer.java | 2 +- .../jaxrs/v1_0/JaxRsAnnotationsTracer.java | 2 +- .../jaxrs/v2_0/JaxRsAnnotationsTracer.java | 2 +- .../jaxws/common/JaxWsTracer.java | 2 +- .../methods/MethodInstrumenters.java | 2 +- .../otelannotations/WithSpanTracer.java | 4 +- .../rediscala/RediscalaClientTracer.java | 4 +- .../servlet/v5_0/response/ResponseTracer.java | 2 +- .../javax/response/ResponseTracer.java | 2 +- .../aspects/WithSpanAspectTracer.java | 2 +- .../spring/data/SpringDataTracer.java | 2 +- .../scheduling/SpringSchedulingTracer.java | 4 +- .../spring/webflux/server/AdviceUtils.java | 4 +- .../server/HandlerAdapterInstrumentation.java | 2 +- .../HandlerSpanNameExtractor.java | 2 +- .../ModelAndViewAttributesExtractor.java | 4 +- .../spring/ws/SpringWsTracer.java | 2 +- .../struts2/Struts2Tracer.java | 2 +- .../instrumentation/twilio/TwilioTracer.java | 2 +- .../instrumentation/vaadin/VaadinTracer.java | 8 ++-- 27 files changed, 98 insertions(+), 76 deletions(-) create mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java index 96198b9afdc0..bc54eaa8523f 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.code; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.tracer.ClassNames; /** * A helper {@link SpanNameExtractor} implementation for instrumentations that target specific Java @@ -33,7 +33,7 @@ private CodeSpanNameExtractor(CodeAttributesExtractor attributesExtr public String extract(REQUEST request) { Class cls = attributesExtractor.codeClass(request); // TODO: avoid using SpanNames, encapsulate the logic here - String className = cls != null ? SpanNames.spanNameForClass(cls) : ""; + String className = cls != null ? ClassNames.simpleName(cls) : ""; String methodName = defaultString(attributesExtractor.methodName(request)); return className + "." + methodName; } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java new file mode 100644 index 000000000000..83c9f83c6a35 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java @@ -0,0 +1,27 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.tracer; + +public class ClassNames { + + /** + * This method is used to generate a simple name based on a given class reference, e.g. for use in + * span names and span attributes. Anonymous classes are named based on their parent. + */ + public static String simpleName(Class clazz) { + if (!clazz.isAnonymousClass()) { + return clazz.getSimpleName(); + } + String className = clazz.getName(); + if (clazz.getPackage() != null) { + String pkgName = clazz.getPackage().getName(); + if (!pkgName.isEmpty()) { + className = className.substring(pkgName.length() + 1); + } + } + return className; + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java index 00239955b099..8e731a3aa1f9 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java @@ -48,7 +48,7 @@ protected HttpServerTracer(OpenTelemetry openTelemetry) { } public Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin) { - String spanName = SpanNames.spanNameForMethod(origin); + String spanName = SpanNames.from(origin); return startSpan(request, connection, storage, spanName); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java index b967eb9213b1..d4af98260aa6 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java @@ -10,45 +10,27 @@ public final class SpanNames { /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. + * This method is used to generate an acceptable span name based on a given method reference. + * Anonymous classes are named based on their parent. */ - public static String spanNameForMethod(Method method) { - return spanNameForMethod(method.getDeclaringClass(), method.getName()); + public static String from(Method method) { + return from(method.getDeclaringClass(), method.getName()); } /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. + * This method is used to generate an acceptable span name based on a given method reference. + * Anonymous classes are named based on their parent. */ - public static String spanNameForMethod(Class clazz, @Nullable Method method) { - return spanNameForMethod(clazz, method == null ? "" : method.getName()); + public static String from(Class clazz, @Nullable Method method) { + return from(clazz, method == null ? "" : method.getName()); } /** - * This method is used to generate an acceptable span (operation) name based on a given method - * reference. Anonymous classes are named based on their parent. + * This method is used to generate an acceptable span name based on a given method reference. + * Anonymous classes are named based on their parent. */ - public static String spanNameForMethod(Class cl, String methodName) { - return spanNameForClass(cl) + "." + methodName; - } - - /** - * This method is used to generate an acceptable span (operation) name based on a given class - * reference. Anonymous classes are named based on their parent. - */ - public static String spanNameForClass(Class clazz) { - if (!clazz.isAnonymousClass()) { - return clazz.getSimpleName(); - } - String className = clazz.getName(); - if (clazz.getPackage() != null) { - String pkgName = clazz.getPackage().getName(); - if (!pkgName.isEmpty()) { - className = className.substring(pkgName.length() + 1); - } - } - return className; + public static String from(Class cl, String methodName) { + return ClassNames.simpleName(cl) + "." + methodName; } private SpanNames() {} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy index 5b506e92dd7a..e732315807d9 100644 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy +++ b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy @@ -10,9 +10,9 @@ import spock.lang.Specification class SpanNamesTest extends Specification { - def "test spanNameForClass"() { + def "test from Class"() { when: - String result = SpanNames.spanNameForClass(clazz) + String result = ClassNames.simpleName(clazz) then: result == expected @@ -23,29 +23,42 @@ class SpanNamesTest extends Specification { SpanNames | "SpanNames" } - def "test spanNameForMethod"() { + def "test from Method"() { when: - String result = SpanNames.spanNameForMethod(method) + String result = SpanNames.from(method) then: result == expected where: - method | expected - ReflectionUtil.getMethodByName(SpanNames, "spanNameForClass") | "SpanNames.spanNameForClass" - ReflectionUtil.getMethodByName(String, "length") | "String.length" + method | expected + ReflectionUtil.getMethodByName(SpanNames, "from") | "SpanNames.from" + ReflectionUtil.getMethodByName(String, "length") | "String.length" } - def "test spanNameForMethod with class"() { + def "test from Class and Method"() { when: - String result = SpanNames.spanNameForMethod(clazz, method) + String result = SpanNames.from(clazz, method) then: result == expected where: - clazz | method | expected - SpanNames | ReflectionUtil.getMethodByName(SpanNames, "spanNameForClass") | "SpanNames.spanNameForClass" - SpanNames | "test" | "SpanNames.test" + clazz = SpanNames + method = ReflectionUtil.getMethodByName(SpanNames, "from") + expected = "SpanNames.from" + } + + def "test from Class and method name"() { + when: + String result = SpanNames.from(clazz, method) + + then: + result == expected + + where: + clazz = SpanNames + method = "test" + expected = "SpanNames.test" } } diff --git a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java index 1958ee00a92e..5c3c22cdb3e6 100644 --- a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java +++ b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.spanNameForMethod(method)); + return startSpan(SpanNames.from(method)); } } diff --git a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java index afcfd80d283e..d9c08ef792a6 100644 --- a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java +++ b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraTracer.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.tracer.ClassNames; public class FinatraTracer extends BaseTracer { private static final FinatraTracer TRACER = new FinatraTracer(); @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Context parentContext, Class clazz) { - return super.startSpan(parentContext, SpanNames.spanNameForClass(clazz), SpanKind.INTERNAL); + return super.startSpan(parentContext, ClassNames.simpleName(clazz), SpanKind.INTERNAL); } } diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java index b4096928dacc..4014e4cfa60a 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java @@ -23,7 +23,7 @@ public static GrailsTracer tracer() { } public Context startSpan(Object controller, String action) { - return startSpan(SpanNames.spanNameForClass(controller.getClass()) + "." + action); + return startSpan(SpanNames.from(controller.getClass(), action)); } public void updateServerSpanName(Context context, GrailsControllerUrlMappingInfo info) { diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java index b776eab6f45b..8d2f985c180d 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java @@ -48,7 +48,7 @@ public Context startSpan(Class target, Method method) { if (serverSpan == null) { spanName = pathBasedSpanName; } else { - spanName = SpanNames.spanNameForMethod(target, method); + spanName = SpanNames.from(target, method); updateServerSpanName(parentContext, serverSpan, pathBasedSpanName); } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java index 32b26ff228fc..b098f5ca48a3 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java @@ -70,7 +70,7 @@ public void updateSpanNames( } else { ServerSpanNaming.updateServerSpanName( context, ServerSpanNaming.Source.CONTROLLER, spanNameSupplier); - updateSpanName(span, SpanNames.spanNameForMethod(target, method)); + updateSpanName(span, SpanNames.from(target, method)); } } diff --git a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java index f39b78cb848c..aecc70df42b0 100644 --- a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java +++ b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java @@ -29,7 +29,7 @@ protected String getInstrumentationName() { } public Context startSpan(Class target, Method method) { - String spanName = SpanNames.spanNameForMethod(target, method); + String spanName = SpanNames.from(target, method); Context parentContext = Context.current(); Span serverSpan = ServerSpan.fromContextOrNull(parentContext); diff --git a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java index 8d30c966aa6f..077d519c31c6 100644 --- a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java +++ b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java @@ -19,7 +19,7 @@ public final class MethodInstrumenters { private static final Instrumenter INSTRUMENTER; static { - SpanNameExtractor spanName = SpanNames::spanNameForMethod; + SpanNameExtractor spanName = SpanNames::from; INSTRUMENTER = Instrumenter.newBuilder( diff --git a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java index 1fc38c21f6ab..c41270cdfe43 100644 --- a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java +++ b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java @@ -48,13 +48,13 @@ parentContext, spanNameForMethodWithAnnotation(applicationAnnotation, method), k * This method is used to generate an acceptable span (operation) name based on a given method * reference. It first checks for existence of {@link WithSpan} annotation. If it is present, then * tries to derive name from its {@code value} attribute. Otherwise delegates to {@link - * SpanNames#spanNameForMethod(Method)}. + * SpanNames#from(Method)}. */ public String spanNameForMethodWithAnnotation(WithSpan applicationAnnotation, Method method) { if (applicationAnnotation != null && !applicationAnnotation.value().isEmpty()) { return applicationAnnotation.value(); } - return SpanNames.spanNameForMethod(method); + return SpanNames.from(method); } public SpanKind extractSpanKind(WithSpan applicationAnnotation) { diff --git a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java index 2689bd8bdc20..0fe07e4cee7d 100644 --- a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java +++ b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTracer.java @@ -5,8 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.rediscala; +import io.opentelemetry.instrumentation.api.tracer.ClassNames; import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes.DbSystemValues; import java.net.InetSocketAddress; @@ -27,7 +27,7 @@ public static RediscalaClientTracer tracer() { @Override protected String sanitizeStatement(RedisCommand redisCommand) { - return SpanNames.spanNameForClass(redisCommand.getClass()); + return ClassNames.simpleName(redisCommand.getClass()); } @Override diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java index f3cc52e8ece2..202c5f36c3cd 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.spanNameForMethod(method)); + return startSpan(SpanNames.from(method)); } } diff --git a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java index 875bf6e4def8..da22335441fe 100644 --- a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.spanNameForMethod(method)); + return startSpan(SpanNames.from(method)); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java index cc461119f78b..ca8f761054f8 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java @@ -45,7 +45,7 @@ Context startSpan(Context parentContext, WithSpan annotation, Method method) { private static String spanName(WithSpan annotation, Method method) { String spanName = annotation.value(); if (spanName.isEmpty()) { - return SpanNames.spanNameForMethod(method); + return SpanNames.from(method); } return spanName; } diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java index c48dd8a85641..08bd55441a5c 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java @@ -25,6 +25,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.spanNameForMethod(method)); + return startSpan(SpanNames.from(method)); } } diff --git a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java index 207f184871fc..afdb67c4d734 100644 --- a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java +++ b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java @@ -30,9 +30,9 @@ public Context startSpan(Runnable runnable) { private static String spanNameOnRun(Runnable runnable) { if (runnable instanceof ScheduledMethodRunnable) { ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable; - return SpanNames.spanNameForMethod(scheduledMethodRunnable.getMethod()); + return SpanNames.from(scheduledMethodRunnable.getMethod()); } else { - return SpanNames.spanNameForClass(runnable.getClass()) + "/run"; + return SpanNames.from(runnable.getClass(), "run"); } } } diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java index 9a6f56055d8b..fcbafa6a5d82 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.tracer.ClassNames; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; @@ -26,7 +26,7 @@ public class AdviceUtils { public static final String CONTEXT_ATTRIBUTE = AdviceUtils.class.getName() + ".Context"; public static String parseOperationName(Object handler) { - String className = SpanNames.spanNameForClass(handler.getClass()); + String className = ClassNames.simpleName(handler.getClass()); String operationName; int lambdaIdx = className.indexOf("$$Lambda$"); diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java index f9451a9b8b74..e8ba9e7a9a76 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java @@ -74,7 +74,7 @@ public static void methodEnter( if (handler instanceof HandlerMethod) { // Special case for requests mapped with annotations HandlerMethod handlerMethod = (HandlerMethod) handler; - operationName = SpanNames.spanNameForMethod(handlerMethod.getMethod()); + operationName = SpanNames.from(handlerMethod.getMethod()); handlerType = handlerMethod.getMethod().getDeclaringClass().getName(); } else { operationName = AdviceUtils.parseOperationName(handler); diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java index 1d2fd79c7e1c..cf0a8a39b4b6 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java @@ -42,6 +42,6 @@ public String extract(Object handler) { methodName = ""; } - return SpanNames.spanNameForMethod(clazz, methodName); + return SpanNames.from(clazz, methodName); } } diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java index 5285652b6765..f9840cd501e6 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.tracer.ClassNames; import org.checkerframework.checker.nullness.qual.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; @@ -26,7 +26,7 @@ protected void onStart(AttributesBuilder attributes, ModelAndView modelAndView) attributes.put("spring-webmvc.view.name", modelAndView.getViewName()); View view = modelAndView.getView(); if (view != null) { - attributes.put("spring-webmvc.view.type", SpanNames.spanNameForClass(view.getClass())); + attributes.put("spring-webmvc.view.type", ClassNames.simpleName(view.getClass())); } } } diff --git a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java index f212d8f5d54c..516207650350 100644 --- a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java +++ b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java @@ -24,7 +24,7 @@ public static SpringWsTracer tracer() { public Context startSpan(Method method) { Context parentContext = Context.current(); Span span = - spanBuilder(parentContext, SpanNames.spanNameForMethod(method), SpanKind.INTERNAL) + spanBuilder(parentContext, SpanNames.from(method), SpanKind.INTERNAL) .setAttribute(SemanticAttributes.CODE_NAMESPACE, method.getDeclaringClass().getName()) .setAttribute(SemanticAttributes.CODE_FUNCTION, method.getName()) .startSpan(); diff --git a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java index 694452d03c75..fe07e2aa778b 100644 --- a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java +++ b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java @@ -31,7 +31,7 @@ public Context startSpan(Context parentContext, ActionInvocation actionInvocatio Class actionClass = action.getClass(); String method = actionInvocation.getProxy().getMethod(); - String spanName = SpanNames.spanNameForMethod(actionClass, method); + String spanName = SpanNames.from(actionClass, method); SpanBuilder strutsSpan = spanBuilder(parentContext, spanName, INTERNAL); diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java index 59438dbb27d5..fbc031b9f279 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java @@ -47,7 +47,7 @@ public Context startSpan(Context parentContext, Object serviceExecutor, String m /** Decorate trace based on service execution metadata. */ private static String spanNameOnServiceExecution(Object serviceExecutor, String methodName) { - return SpanNames.spanNameForMethod(serviceExecutor.getClass(), methodName); + return SpanNames.from(serviceExecutor.getClass(), methodName); } /** Annotate the span with the results of the operation. */ diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java index 22320512d0e5..c0a36921cd08 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java @@ -39,7 +39,7 @@ private VaadinTracer() { } public Context startVaadinServiceSpan(VaadinService vaadinService, Method method) { - String spanName = SpanNames.spanNameForMethod(vaadinService.getClass(), method); + String spanName = SpanNames.from(vaadinService.getClass(), method); Context context = super.startSpan(spanName); return context.with(SERVICE_CONTEXT_KEY, new VaadinServiceContext(spanName)); } @@ -76,7 +76,7 @@ public Context startRequestHandlerSpan(RequestHandler requestHandler, Method met return null; } - String spanName = SpanNames.spanNameForMethod(requestHandler.getClass(), method); + String spanName = SpanNames.from(requestHandler.getClass(), method); VaadinServiceContext vaadinServiceContext = current.get(SERVICE_CONTEXT_KEY); if (vaadinServiceContext != null && !vaadinServiceContext.isRequestHandled()) { Span span = ServerSpan.fromContextOrNull(current); @@ -126,12 +126,12 @@ public void updateServerSpanName(Location location) { } public Context startClientCallableSpan(Class componentClass, String methodName) { - return super.startSpan(SpanNames.spanNameForMethod(componentClass, methodName)); + return super.startSpan(SpanNames.from(componentClass, methodName)); } public Context startRpcInvocationHandlerSpan( RpcInvocationHandler rpcInvocationHandler, Method method, JsonObject jsonObject) { - String spanName = SpanNames.spanNameForMethod(rpcInvocationHandler.getClass(), method); + String spanName = SpanNames.from(rpcInvocationHandler.getClass(), method); if ("event".equals(rpcInvocationHandler.getRpcType())) { String eventType = jsonObject.getString("event"); if (eventType != null) { From 582deebe51abb2058e0ac90c1dd1812b4e393aa7 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 14:04:03 -0700 Subject: [PATCH 5/8] Rename --- .../api/tracer/HttpServerTracer.java | 2 +- .../instrumentation/api/tracer/SpanNames.java | 22 +++++++++---------- .../api/tracer/SpanNamesTest.groovy | 6 ++--- .../ExternalAnnotationTracer.java | 2 +- .../instrumentation/grails/GrailsTracer.java | 2 +- .../jaxrs/v1_0/JaxRsAnnotationsTracer.java | 2 +- .../jaxrs/v2_0/JaxRsAnnotationsTracer.java | 2 +- .../jaxws/common/JaxWsTracer.java | 2 +- .../methods/MethodInstrumenters.java | 2 +- .../otelannotations/WithSpanTracer.java | 4 ++-- .../servlet/v5_0/response/ResponseTracer.java | 2 +- .../javax/response/ResponseTracer.java | 2 +- .../aspects/WithSpanAspectTracer.java | 2 +- .../spring/data/SpringDataTracer.java | 2 +- .../scheduling/SpringSchedulingTracer.java | 4 ++-- .../server/HandlerAdapterInstrumentation.java | 2 +- .../HandlerSpanNameExtractor.java | 2 +- .../spring/ws/SpringWsTracer.java | 2 +- .../struts2/Struts2Tracer.java | 2 +- .../instrumentation/twilio/TwilioTracer.java | 2 +- .../instrumentation/vaadin/VaadinTracer.java | 8 +++---- 21 files changed, 38 insertions(+), 38 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java index 8e731a3aa1f9..2550774c8749 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java @@ -48,7 +48,7 @@ protected HttpServerTracer(OpenTelemetry openTelemetry) { } public Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin) { - String spanName = SpanNames.from(origin); + String spanName = SpanNames.fromMethod(origin); return startSpan(request, connection, storage, spanName); } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java index d4af98260aa6..dad2a2bd3cf1 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java @@ -10,26 +10,26 @@ public final class SpanNames { /** - * This method is used to generate an acceptable span name based on a given method reference. - * Anonymous classes are named based on their parent. + * This method is used to generate a span name based on a method. Anonymous classes are named + * based on their parent. */ - public static String from(Method method) { - return from(method.getDeclaringClass(), method.getName()); + public static String fromMethod(Method method) { + return fromMethod(method.getDeclaringClass(), method.getName()); } /** - * This method is used to generate an acceptable span name based on a given method reference. - * Anonymous classes are named based on their parent. + * This method is used to generate a span name based on a method. Anonymous classes are named + * based on their parent. */ - public static String from(Class clazz, @Nullable Method method) { - return from(clazz, method == null ? "" : method.getName()); + public static String fromMethod(Class clazz, @Nullable Method method) { + return fromMethod(clazz, method == null ? "" : method.getName()); } /** - * This method is used to generate an acceptable span name based on a given method reference. - * Anonymous classes are named based on their parent. + * This method is used to generate a span name based on a method. Anonymous classes are named + * based on their parent. */ - public static String from(Class cl, String methodName) { + public static String fromMethod(Class cl, String methodName) { return ClassNames.simpleName(cl) + "." + methodName; } diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy index e732315807d9..753df1688c32 100644 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy +++ b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy @@ -25,7 +25,7 @@ class SpanNamesTest extends Specification { def "test from Method"() { when: - String result = SpanNames.from(method) + String result = SpanNames.fromMethod(method) then: result == expected @@ -38,7 +38,7 @@ class SpanNamesTest extends Specification { def "test from Class and Method"() { when: - String result = SpanNames.from(clazz, method) + String result = SpanNames.fromMethod(clazz, method) then: result == expected @@ -51,7 +51,7 @@ class SpanNamesTest extends Specification { def "test from Class and method name"() { when: - String result = SpanNames.from(clazz, method) + String result = SpanNames.fromMethod(clazz, method) then: result == expected diff --git a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java index 5c3c22cdb3e6..87bdc014cf4d 100644 --- a/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java +++ b/instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extannotations/ExternalAnnotationTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.from(method)); + return startSpan(SpanNames.fromMethod(method)); } } diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java index 4014e4cfa60a..6471c237fa3f 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsTracer.java @@ -23,7 +23,7 @@ public static GrailsTracer tracer() { } public Context startSpan(Object controller, String action) { - return startSpan(SpanNames.from(controller.getClass(), action)); + return startSpan(SpanNames.fromMethod(controller.getClass(), action)); } public void updateServerSpanName(Context context, GrailsControllerUrlMappingInfo info) { diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java index 8d2f985c180d..6db021315e53 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxRsAnnotationsTracer.java @@ -48,7 +48,7 @@ public Context startSpan(Class target, Method method) { if (serverSpan == null) { spanName = pathBasedSpanName; } else { - spanName = SpanNames.from(target, method); + spanName = SpanNames.fromMethod(target, method); updateServerSpanName(parentContext, serverSpan, pathBasedSpanName); } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java index b098f5ca48a3..57cc6cb1412b 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAnnotationsTracer.java @@ -70,7 +70,7 @@ public void updateSpanNames( } else { ServerSpanNaming.updateServerSpanName( context, ServerSpanNaming.Source.CONTROLLER, spanNameSupplier); - updateSpanName(span, SpanNames.from(target, method)); + updateSpanName(span, SpanNames.fromMethod(target, method)); } } diff --git a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java index aecc70df42b0..b263c85bfb16 100644 --- a/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java +++ b/instrumentation/jaxws/jaxws-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/common/JaxWsTracer.java @@ -29,7 +29,7 @@ protected String getInstrumentationName() { } public Context startSpan(Class target, Method method) { - String spanName = SpanNames.from(target, method); + String spanName = SpanNames.fromMethod(target, method); Context parentContext = Context.current(); Span serverSpan = ServerSpan.fromContextOrNull(parentContext); diff --git a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java index 077d519c31c6..4fefef5eec7f 100644 --- a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java +++ b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodInstrumenters.java @@ -19,7 +19,7 @@ public final class MethodInstrumenters { private static final Instrumenter INSTRUMENTER; static { - SpanNameExtractor spanName = SpanNames::from; + SpanNameExtractor spanName = SpanNames::fromMethod; INSTRUMENTER = Instrumenter.newBuilder( diff --git a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java index c41270cdfe43..620f41487ccd 100644 --- a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java +++ b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanTracer.java @@ -48,13 +48,13 @@ parentContext, spanNameForMethodWithAnnotation(applicationAnnotation, method), k * This method is used to generate an acceptable span (operation) name based on a given method * reference. It first checks for existence of {@link WithSpan} annotation. If it is present, then * tries to derive name from its {@code value} attribute. Otherwise delegates to {@link - * SpanNames#from(Method)}. + * SpanNames#fromMethod(Method)}. */ public String spanNameForMethodWithAnnotation(WithSpan applicationAnnotation, Method method) { if (applicationAnnotation != null && !applicationAnnotation.value().isEmpty()) { return applicationAnnotation.value(); } - return SpanNames.from(method); + return SpanNames.fromMethod(method); } public SpanKind extractSpanKind(WithSpan applicationAnnotation) { diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java index 202c5f36c3cd..cfd40e4a1d81 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.from(method)); + return startSpan(SpanNames.fromMethod(method)); } } diff --git a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java index da22335441fe..0e2318403d7b 100644 --- a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java +++ b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseTracer.java @@ -23,6 +23,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.from(method)); + return startSpan(SpanNames.fromMethod(method)); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java index ca8f761054f8..96e74fe63f5c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTracer.java @@ -45,7 +45,7 @@ Context startSpan(Context parentContext, WithSpan annotation, Method method) { private static String spanName(WithSpan annotation, Method method) { String spanName = annotation.value(); if (spanName.isEmpty()) { - return SpanNames.from(method); + return SpanNames.fromMethod(method); } return spanName; } diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java index 08bd55441a5c..8c2a73d4cc1e 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java @@ -25,6 +25,6 @@ protected String getInstrumentationName() { } public Context startSpan(Method method) { - return startSpan(SpanNames.from(method)); + return startSpan(SpanNames.fromMethod(method)); } } diff --git a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java index afdb67c4d734..44c4f7d29b15 100644 --- a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java +++ b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingTracer.java @@ -30,9 +30,9 @@ public Context startSpan(Runnable runnable) { private static String spanNameOnRun(Runnable runnable) { if (runnable instanceof ScheduledMethodRunnable) { ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable; - return SpanNames.from(scheduledMethodRunnable.getMethod()); + return SpanNames.fromMethod(scheduledMethodRunnable.getMethod()); } else { - return SpanNames.from(runnable.getClass(), "run"); + return SpanNames.fromMethod(runnable.getClass(), "run"); } } } diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java index e8ba9e7a9a76..a3795a056945 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/HandlerAdapterInstrumentation.java @@ -74,7 +74,7 @@ public static void methodEnter( if (handler instanceof HandlerMethod) { // Special case for requests mapped with annotations HandlerMethod handlerMethod = (HandlerMethod) handler; - operationName = SpanNames.from(handlerMethod.getMethod()); + operationName = SpanNames.fromMethod(handlerMethod.getMethod()); handlerType = handlerMethod.getMethod().getDeclaringClass().getName(); } else { operationName = AdviceUtils.parseOperationName(handler); diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java index cf0a8a39b4b6..3e75809d06aa 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java @@ -42,6 +42,6 @@ public String extract(Object handler) { methodName = ""; } - return SpanNames.from(clazz, methodName); + return SpanNames.fromMethod(clazz, methodName); } } diff --git a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java index 516207650350..f7dec5a6eefb 100644 --- a/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java +++ b/instrumentation/spring/spring-ws-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/ws/SpringWsTracer.java @@ -24,7 +24,7 @@ public static SpringWsTracer tracer() { public Context startSpan(Method method) { Context parentContext = Context.current(); Span span = - spanBuilder(parentContext, SpanNames.from(method), SpanKind.INTERNAL) + spanBuilder(parentContext, SpanNames.fromMethod(method), SpanKind.INTERNAL) .setAttribute(SemanticAttributes.CODE_NAMESPACE, method.getDeclaringClass().getName()) .setAttribute(SemanticAttributes.CODE_FUNCTION, method.getName()) .startSpan(); diff --git a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java index fe07e2aa778b..8cc99ead34a4 100644 --- a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java +++ b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/Struts2Tracer.java @@ -31,7 +31,7 @@ public Context startSpan(Context parentContext, ActionInvocation actionInvocatio Class actionClass = action.getClass(); String method = actionInvocation.getProxy().getMethod(); - String spanName = SpanNames.from(actionClass, method); + String spanName = SpanNames.fromMethod(actionClass, method); SpanBuilder strutsSpan = spanBuilder(parentContext, spanName, INTERNAL); diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java index fbc031b9f279..02d6879154df 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java @@ -47,7 +47,7 @@ public Context startSpan(Context parentContext, Object serviceExecutor, String m /** Decorate trace based on service execution metadata. */ private static String spanNameOnServiceExecution(Object serviceExecutor, String methodName) { - return SpanNames.from(serviceExecutor.getClass(), methodName); + return SpanNames.fromMethod(serviceExecutor.getClass(), methodName); } /** Annotate the span with the results of the operation. */ diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java index c0a36921cd08..1467a0aae372 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinTracer.java @@ -39,7 +39,7 @@ private VaadinTracer() { } public Context startVaadinServiceSpan(VaadinService vaadinService, Method method) { - String spanName = SpanNames.from(vaadinService.getClass(), method); + String spanName = SpanNames.fromMethod(vaadinService.getClass(), method); Context context = super.startSpan(spanName); return context.with(SERVICE_CONTEXT_KEY, new VaadinServiceContext(spanName)); } @@ -76,7 +76,7 @@ public Context startRequestHandlerSpan(RequestHandler requestHandler, Method met return null; } - String spanName = SpanNames.from(requestHandler.getClass(), method); + String spanName = SpanNames.fromMethod(requestHandler.getClass(), method); VaadinServiceContext vaadinServiceContext = current.get(SERVICE_CONTEXT_KEY); if (vaadinServiceContext != null && !vaadinServiceContext.isRequestHandled()) { Span span = ServerSpan.fromContextOrNull(current); @@ -126,12 +126,12 @@ public void updateServerSpanName(Location location) { } public Context startClientCallableSpan(Class componentClass, String methodName) { - return super.startSpan(SpanNames.from(componentClass, methodName)); + return super.startSpan(SpanNames.fromMethod(componentClass, methodName)); } public Context startRpcInvocationHandlerSpan( RpcInvocationHandler rpcInvocationHandler, Method method, JsonObject jsonObject) { - String spanName = SpanNames.from(rpcInvocationHandler.getClass(), method); + String spanName = SpanNames.fromMethod(rpcInvocationHandler.getClass(), method); if ("event".equals(rpcInvocationHandler.getRpcType())) { String eventType = jsonObject.getString("event"); if (eventType != null) { From ba7591505bc88ba1ff8b8b2b2d8ba0526906e7af Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 14:13:22 -0700 Subject: [PATCH 6/8] Fix up tests --- .../api/tracer/ClassNamesTest.groovy | 24 +++++++++++++++ .../api/tracer/SpanNamesTest.groovy | 29 +++++-------------- 2 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy new file mode 100644 index 000000000000..c8718fd5e7e9 --- /dev/null +++ b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.tracer + +import spock.lang.Specification + +class ClassNamesTest extends Specification { + + def "test simpleName"() { + when: + String result = ClassNames.simpleName(clazz) + + then: + result == expected + + where: + clazz | expected + ClassNamesTest | "ClassNamesTest" + ClassNames | "ClassNames" + } +} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy index 753df1688c32..a835a189f9d0 100644 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy +++ b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy @@ -10,20 +10,7 @@ import spock.lang.Specification class SpanNamesTest extends Specification { - def "test from Class"() { - when: - String result = ClassNames.simpleName(clazz) - - then: - result == expected - - where: - clazz | expected - SpanNamesTest | "SpanNamesTest" - SpanNames | "SpanNames" - } - - def "test from Method"() { + def "test fromMethod"() { when: String result = SpanNames.fromMethod(method) @@ -31,12 +18,12 @@ class SpanNamesTest extends Specification { result == expected where: - method | expected - ReflectionUtil.getMethodByName(SpanNames, "from") | "SpanNames.from" - ReflectionUtil.getMethodByName(String, "length") | "String.length" + method | expected + ReflectionUtil.getMethodByName(SpanNames, "fromMethod") | "SpanNames.fromMethod" + ReflectionUtil.getMethodByName(String, "length") | "String.length" } - def "test from Class and Method"() { + def "test fromMethod with class and method ref"() { when: String result = SpanNames.fromMethod(clazz, method) @@ -45,11 +32,11 @@ class SpanNamesTest extends Specification { where: clazz = SpanNames - method = ReflectionUtil.getMethodByName(SpanNames, "from") - expected = "SpanNames.from" + method = ReflectionUtil.getMethodByName(SpanNames, "fromMethod") + expected = "SpanNames.fromMethod" } - def "test from Class and method name"() { + def "test fromMethod with class and method name"() { when: String result = SpanNames.fromMethod(clazz, method) From cdcfe7b7b4bcd8b23a694da1594114a1151266a2 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 13 Jun 2021 19:33:42 -0700 Subject: [PATCH 7/8] Cache simple name using ClassValue --- .../api/tracer/ClassNames.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java index 83c9f83c6a35..7c1f7ee4d15f 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java @@ -7,21 +7,29 @@ public class ClassNames { + private static final ClassValue simpleNames = + new ClassValue() { + @Override + protected String computeValue(Class type) { + if (!type.isAnonymousClass()) { + return type.getSimpleName(); + } + String className = type.getName(); + if (type.getPackage() != null) { + String pkgName = type.getPackage().getName(); + if (!pkgName.isEmpty()) { + className = className.substring(pkgName.length() + 1); + } + } + return className; + } + }; + /** * This method is used to generate a simple name based on a given class reference, e.g. for use in * span names and span attributes. Anonymous classes are named based on their parent. */ - public static String simpleName(Class clazz) { - if (!clazz.isAnonymousClass()) { - return clazz.getSimpleName(); - } - String className = clazz.getName(); - if (clazz.getPackage() != null) { - String pkgName = clazz.getPackage().getName(); - if (!pkgName.isEmpty()) { - className = className.substring(pkgName.length() + 1); - } - } - return className; + public static String simpleName(Class type) { + return simpleNames.get(type); } } From e4827d8d54ac9567d694382084cc0b942dfc0723 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 14 Jun 2021 10:22:06 -0700 Subject: [PATCH 8/8] Review feedback --- .../api/instrumenter/code/CodeSpanNameExtractor.java | 1 - .../opentelemetry/instrumentation/api/tracer/ClassNames.java | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java index bc54eaa8523f..ac0cc835cd53 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java @@ -32,7 +32,6 @@ private CodeSpanNameExtractor(CodeAttributesExtractor attributesExtr @Override public String extract(REQUEST request) { Class cls = attributesExtractor.codeClass(request); - // TODO: avoid using SpanNames, encapsulate the logic here String className = cls != null ? ClassNames.simpleName(cls) : ""; String methodName = defaultString(attributesExtractor.methodName(request)); return className + "." + methodName; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java index 7c1f7ee4d15f..8e3865fb36e2 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.api.tracer; -public class ClassNames { +public final class ClassNames { private static final ClassValue simpleNames = new ClassValue() { @@ -32,4 +32,6 @@ protected String computeValue(Class type) { public static String simpleName(Class type) { return simpleNames.get(type); } + + private ClassNames() {} }