diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-api.txt b/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-api.txt index c09bab2b8f36..767e445ba09b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-api.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-instrumentation-api.txt @@ -1,2 +1,6 @@ Comparing source compatibility of opentelemetry-instrumentation-api-2.11.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.10.0.jar -No changes. \ No newline at end of file ++++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.instrumentation.api.semconv.util.SpanNames (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) STATIC(+) java.lang.String fromMethod(java.lang.reflect.Method) + +++ NEW METHOD: PUBLIC(+) STATIC(+) java.lang.String fromMethod(java.lang.Class, java.lang.String) diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/util/SpanNames.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/util/SpanNames.java index 7962b0474333..6d9f799436a3 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/util/SpanNames.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/util/SpanNames.java @@ -5,22 +5,21 @@ package io.opentelemetry.instrumentation.api.incubator.semconv.util; -import io.opentelemetry.instrumentation.api.internal.ClassNames; -import io.opentelemetry.instrumentation.api.internal.cache.Cache; import java.lang.reflect.Method; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +/** + * This class has been stabilized and moved to {@link + * io.opentelemetry.instrumentation.api.semconv.util.SpanNames} + */ +@Deprecated public final class SpanNames { - private static final Cache, Map> spanNameCaches = Cache.weak(); - /** * This method is used to generate a span name based on a method. Anonymous classes are named * based on their parent. */ public static String fromMethod(Method method) { - return fromMethod(method.getDeclaringClass(), method.getName()); + return io.opentelemetry.instrumentation.api.semconv.util.SpanNames.fromMethod(method); } /** @@ -28,18 +27,8 @@ public static String fromMethod(Method method) { * based on their parent. */ public static String fromMethod(Class clazz, String methodName) { - // the cache (ConcurrentHashMap) is naturally bounded by the number of methods in a class - Map spanNameCache = - spanNameCaches.computeIfAbsent(clazz, c -> new ConcurrentHashMap<>()); - - // not using computeIfAbsent, because it would require a capturing (allocating) lambda - String spanName = spanNameCache.get(methodName); - if (spanName != null) { - return spanName; - } - spanName = ClassNames.simpleName(clazz) + "." + methodName; - spanNameCache.put(methodName, spanName); - return spanName; + return io.opentelemetry.instrumentation.api.semconv.util.SpanNames.fromMethod( + clazz, methodName); } private SpanNames() {} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNames.java new file mode 100644 index 000000000000..4dfffeaa8e0c --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNames.java @@ -0,0 +1,47 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.semconv.util; + +import io.opentelemetry.instrumentation.api.internal.ClassNames; +import io.opentelemetry.instrumentation.api.internal.cache.Cache; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** A utility class used to generate span names. */ +public final class SpanNames { + + private static final Cache, Map> spanNameCaches = Cache.weak(); + + /** + * This method is used to generate a span name based on a method. Anonymous classes are named + * based on their parent. + */ + public static String fromMethod(Method method) { + return fromMethod(method.getDeclaringClass(), method.getName()); + } + + /** + * This method is used to generate a span name based on a method. Anonymous classes are named + * based on their parent. + */ + public static String fromMethod(Class clazz, String methodName) { + // the cache (ConcurrentHashMap) is naturally bounded by the number of methods in a class + Map spanNameCache = + spanNameCaches.computeIfAbsent(clazz, c -> new ConcurrentHashMap<>()); + + // not using computeIfAbsent, because it would require a capturing (allocating) lambda + String spanName = spanNameCache.get(methodName); + if (spanName != null) { + return spanName; + } + spanName = ClassNames.simpleName(clazz) + "." + methodName; + spanNameCache.put(methodName, spanName); + return spanName; + } + + private SpanNames() {} +} diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNamesTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNamesTest.java new file mode 100644 index 000000000000..dde0647db52d --- /dev/null +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/util/SpanNamesTest.java @@ -0,0 +1,25 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.semconv.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.lang.reflect.Method; +import org.junit.jupiter.api.Test; + +class SpanNamesTest { + @Test + void testFromMethod() throws NoSuchMethodException { + Method method = TestClass.class.getMethod("test"); + assertThat(SpanNames.fromMethod(method)).isEqualTo("TestClass.test"); + } + + static class TestClass { + private TestClass() {} + + public void test() {} + } +} diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java index cc09d92aa9cd..6427f466d13f 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.grails; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; public class HandlerData { diff --git a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/AnnotationSingletons.java b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/AnnotationSingletons.java index 134b1a3ac309..88d6af48f2f0 100644 --- a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/AnnotationSingletons.java +++ b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/AnnotationSingletons.java @@ -7,8 +7,8 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; public final class AnnotationSingletons { diff --git a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/WithSpanSingletons.java b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/WithSpanSingletons.java index ea29e091a461..cebd4bd009c3 100644 --- a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/WithSpanSingletons.java +++ b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/WithSpanSingletons.java @@ -11,8 +11,8 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import java.lang.reflect.Method; import java.util.logging.Logger; diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/AnnotationSingletons.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/AnnotationSingletons.java index ff1d75aec95e..4e268ebf496b 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/AnnotationSingletons.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/AnnotationSingletons.java @@ -13,8 +13,8 @@ import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; import io.opentelemetry.instrumentation.api.annotation.support.SpanAttributesExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import java.lang.reflect.Method; import java.util.logging.Logger; diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/JoinPointRequest.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/JoinPointRequest.java index 01a6a62d9894..4189c6cb3060 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/JoinPointRequest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/JoinPointRequest.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.annotations.WithSpan; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import java.lang.reflect.Method; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.reflect.MethodSignature; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSpanNameExtractor.java b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSpanNameExtractor.java index 9ab4ae97d3f5..03189d3f0c71 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSpanNameExtractor.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/WebfluxSpanNameExtractor.java @@ -6,8 +6,8 @@ package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeSpanNameExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import org.springframework.web.method.HandlerMethod; public class WebfluxSpanNameExtractor implements SpanNameExtractor { diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/HandlerSpanNameExtractor.java b/instrumentation/spring/spring-webmvc/spring-webmvc-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/HandlerSpanNameExtractor.java index a37ebf617784..1c332828ba6d 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/HandlerSpanNameExtractor.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webmvc/HandlerSpanNameExtractor.java @@ -5,8 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.spring.webmvc; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import java.lang.reflect.Method; import javax.annotation.Nullable; import org.springframework.web.HttpRequestHandler; diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java index 3c6b3296e125..106ad4873ce3 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java @@ -8,9 +8,9 @@ import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; public final class TwilioSingletons { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java index 0a820e9aa988..15025350dd57 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.vaadin; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; @AutoValue public abstract class VaadinHandlerRequest { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java index 02bfcf2b1a69..9bca796e79d9 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.vaadin; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; @AutoValue public abstract class VaadinServiceRequest { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java index 2422b9a1d82a..c3ff8e879282 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java @@ -10,8 +10,8 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeSpanNameExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.util.SpanNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.semconv.util.SpanNames; import io.opentelemetry.javaagent.bootstrap.internal.ExperimentalConfig; public class VaadinSingletons {