From 6a24080fe9f624510bdc1dc618bd0dc6364e1219 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 27 Jul 2022 09:37:01 +0200 Subject: [PATCH] Add code attributes to several instrumentations (#6365) * Add code attributes to several instrumentations * fix servlet tests * fix tests * fix elasticsearch tests * fix context bridge test * fix rxjava tests * fix spring webmvc tests --- .../otelannotations/AbstractWithSpanTest.java | 43 +++++++--- .../instrumentation/api/util/SpanNames.java | 8 ++ ...Elasticsearch53SpringRepositoryTest.groovy | 14 ++++ .../methods/MethodSingletons.java | 13 ++- .../instrumentation/methods/MethodTest.java | 12 ++- .../src/test/groovy/ContextBridgeTest.groovy | 23 ++++-- .../MethodCodeAttributesGetter.java | 23 ++++++ .../MethodRequestCodeAttributesGetter.java | 22 +++++ .../WithSpanSingletons.java | 4 + .../groovy/WithSpanInstrumentationTest.groovy | 35 ++++++++ .../MethodCodeAttributesGetter.java | 23 ++++++ .../MethodRequestCodeAttributesGetter.java | 22 +++++ .../WithSpanSingletons.java | 4 + .../groovy/WithSpanInstrumentationTest.groovy | 35 ++++++++ .../reactor/BaseFluxWithSpanTest.java | 30 ++++--- .../reactor/BaseMonoWithSpanTest.java | 34 +++++--- .../RxJava2WithSpanInstrumentationTest.groovy | 69 ++++++++++++++++ ...tRxJava3WithSpanInstrumentationTest.groovy | 69 ++++++++++++++++ .../groovy/HttpServletResponseTest.groovy | 8 ++ .../src/test/groovy/JettyServlet2Test.groovy | 6 +- .../groovy/HttpServletResponseTest.groovy | 8 ++ .../response/ResponseInstrumenterFactory.java | 11 ++- .../JointPointCodeAttributesExtractor.java | 22 +++++ .../autoconfigure/aspects/WithSpanAspect.java | 3 + .../aspects/WithSpanAspectTest.java | 81 ++++++++++++++----- .../spring/data/SpringDataSingletons.java | 22 +++-- .../src/test/groovy/SpringJpaTest.groovy | 12 +++ .../test/boot/SpringBootBasedTest.groovy | 8 +- 28 files changed, 585 insertions(+), 79 deletions(-) create mode 100644 instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodCodeAttributesGetter.java create mode 100644 instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodRequestCodeAttributesGetter.java create mode 100644 instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodCodeAttributesGetter.java create mode 100644 instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodRequestCodeAttributesGetter.java create mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/JointPointCodeAttributesExtractor.java diff --git a/instrumentation-annotations-support-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/AbstractWithSpanTest.java b/instrumentation-annotations-support-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/AbstractWithSpanTest.java index 5f10e0d889bd..2d1a03aa8193 100644 --- a/instrumentation-annotations-support-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/AbstractWithSpanTest.java +++ b/instrumentation-annotations-support-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/AbstractWithSpanTest.java @@ -5,11 +5,13 @@ package io.opentelemetry.javaagent.instrumentation.otelannotations; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry; +import static io.opentelemetry.api.common.AttributeKey.booleanKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_FUNCTION; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_NAMESPACE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; -import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; @@ -42,7 +44,8 @@ protected final InstrumentationExtension testing() { @Test void success() { - T future = newTraced().completable(); + AbstractTraced traced = newTraced(); + T future = traced.completable(); complete(future, AbstractTraced.SUCCESS_VALUE); assertThat(getCompleted(future)).isEqualTo(AbstractTraced.SUCCESS_VALUE); @@ -54,12 +57,15 @@ void success() { span.hasName("Traced.completable") .hasKind(SpanKind.INTERNAL) .hasNoParent() - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "completable")))); } @Test void failure() { - T future = newTraced().completable(); + AbstractTraced traced = newTraced(); + T future = traced.completable(); fail(future, AbstractTraced.FAILURE); Throwable thrown = catchThrowable(() -> getCompleted(future)); @@ -74,12 +80,15 @@ void failure() { .hasNoParent() .hasStatus(StatusData.error()) .hasException(AbstractTraced.FAILURE) - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "completable")))); } @Test void canceled() { - T future = newTraced().completable(); + AbstractTraced traced = newTraced(); + T future = traced.completable(); cancel(future); testing.waitAndAssertTraces( @@ -89,13 +98,16 @@ void canceled() { span.hasName("Traced.completable") .hasKind(SpanKind.INTERNAL) .hasNoParent() - .hasAttributes(attributeEntry(canceledKey(), true)))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "completable"), + equalTo(booleanKey(canceledKey()), true)))); } @Test void immediateSuccess() { - assertThat(getCompleted(newTraced().alreadySucceeded())) - .isEqualTo(AbstractTraced.SUCCESS_VALUE); + AbstractTraced traced = newTraced(); + assertThat(getCompleted(traced.alreadySucceeded())).isEqualTo(AbstractTraced.SUCCESS_VALUE); testing.waitAndAssertTraces( trace -> @@ -104,12 +116,15 @@ void immediateSuccess() { span.hasName("Traced.alreadySucceeded") .hasKind(SpanKind.INTERNAL) .hasNoParent() - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "alreadySucceeded")))); } @Test void immediateFailure() { - Throwable error = catchThrowable(() -> getCompleted(newTraced().alreadyFailed())); + AbstractTraced traced = newTraced(); + Throwable error = catchThrowable(() -> getCompleted(traced.alreadyFailed())); assertThat(unwrapError(error)).isEqualTo(AbstractTraced.FAILURE); testing.waitAndAssertTraces( @@ -121,6 +136,8 @@ void immediateFailure() { .hasNoParent() .hasStatus(StatusData.error()) .hasException(AbstractTraced.FAILURE) - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "alreadyFailed")))); } } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/util/SpanNames.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/util/SpanNames.java index 8e1cc31e6b97..b5ef6f3a8276 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/util/SpanNames.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/util/SpanNames.java @@ -5,6 +5,7 @@ package io.opentelemetry.instrumentation.api.util; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor; import io.opentelemetry.instrumentation.api.internal.cache.Cache; import java.lang.reflect.Method; import java.util.Map; @@ -26,7 +27,10 @@ public static String fromMethod(Method method) { /** * This method is used to generate a span name based on a method. Anonymous classes are named * based on their parent. + * + * @deprecated Use {@link #fromMethod(Class, String)} instead. */ + @Deprecated public static String fromMethod(Class clazz, @Nullable Method method) { return fromMethod(clazz, method == null ? "" : method.getName()); } @@ -34,7 +38,11 @@ public static String fromMethod(Class clazz, @Nullable Method method) { /** * This method is used to generate a span name based on a method. Anonymous classes are named * based on their parent. + * + * @deprecated Use {@link ClassAndMethod#codeAttributesGetter()} and {@link CodeSpanNameExtractor} + * instead. */ + @Deprecated public static String fromMethod(ClassAndMethod classAndMethod) { return fromMethod(classAndMethod.declaringClass(), classAndMethod.methodName()); } diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy index daffbae3037e..5fef17105943 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy @@ -84,6 +84,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.findAll" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findAll" } } span(1) { @@ -120,6 +122,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.index" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "index" } } span(1) { @@ -169,6 +173,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.findById" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findById" } } span(1) { @@ -204,6 +210,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.index" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "index" } } span(1) { @@ -245,6 +253,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.findById" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findById" } } span(1) { @@ -279,6 +289,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.deleteById" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "deleteById" } } span(1) { @@ -320,6 +332,8 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat name "DocRepository.findAll" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" DocRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findAll" } } span(1) { diff --git a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java index dfc04b1c55c8..ef5725f870f4 100644 --- a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java +++ b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java @@ -8,9 +8,10 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; -import io.opentelemetry.instrumentation.api.util.SpanNames; public final class MethodSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.methods"; @@ -18,11 +19,15 @@ public final class MethodSingletons { private static final Instrumenter INSTRUMENTER; static { - SpanNameExtractor spanName = SpanNames::fromMethod; + CodeAttributesGetter codeAttributesGetter = + ClassAndMethod.codeAttributesGetter(); INSTRUMENTER = Instrumenter.builder( - GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanName) + GlobalOpenTelemetry.get(), + INSTRUMENTATION_NAME, + CodeSpanNameExtractor.create(codeAttributesGetter)) + .addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter)) .buildInstrumenter(SpanKindExtractor.alwaysInternal()); } diff --git a/instrumentation/methods/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java b/instrumentation/methods/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java index 29d1c35cf1d9..41c75e870c75 100644 --- a/instrumentation/methods/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java +++ b/instrumentation/methods/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java @@ -6,8 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.methods; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_FUNCTION; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_NAMESPACE; -import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; @@ -33,7 +35,9 @@ void methodTraced() { span -> span.hasName("ConfigTracedCallable.call") .hasKind(SpanKind.INTERNAL) - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, ConfigTracedCallable.class.getName()), + equalTo(CODE_FUNCTION, "call")))); } static class ConfigTracedCallable implements Callable { @@ -62,7 +66,9 @@ void methodTracedWithAsyncStop() throws Exception { span -> span.hasName("ConfigTracedCompletableFuture.getResult") .hasKind(SpanKind.INTERNAL) - .hasAttributes(Attributes.empty()))); + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, ConfigTracedCompletableFuture.class.getName()), + equalTo(CODE_FUNCTION, "getResult")))); } static class ConfigTracedCompletableFuture { diff --git a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy index 50fa58f252ff..abbacd956648 100644 --- a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy +++ b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy @@ -10,6 +10,7 @@ import io.opentelemetry.context.Context import io.opentelemetry.context.ContextKey import io.opentelemetry.extension.annotations.WithSpan import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import java.util.concurrent.CountDownLatch import java.util.concurrent.Executors @@ -34,8 +35,8 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { } def "application propagates agent's context"() { - when: - new Runnable() { + given: + def runnable = new Runnable() { @WithSpan("test") @Override void run() { @@ -49,7 +50,10 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { } } } - }.run() + } + + when: + runnable.run() then: assertTraces(1) { @@ -58,6 +62,8 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { name "test" hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" runnable.class.name + "$SemanticAttributes.CODE_FUNCTION" "run" "cat" "yes" } } @@ -92,8 +98,8 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { } def "application propagates agent's span"() { - when: - new Runnable() { + given: + def runnable = new Runnable() { @WithSpan("test") @Override void run() { @@ -107,7 +113,10 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { } } } - }.run() + } + + when: + runnable.run() then: assertTraces(1) { @@ -116,6 +125,8 @@ class ContextBridgeTest extends AgentInstrumentationSpecification { name "test" hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" runnable.class.name + "$SemanticAttributes.CODE_FUNCTION" "run" "cat" "yes" } } diff --git a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodCodeAttributesGetter.java b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodCodeAttributesGetter.java new file mode 100644 index 000000000000..894c02c2a4cf --- /dev/null +++ b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodCodeAttributesGetter.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.extensionannotations; + +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; +import java.lang.reflect.Method; + +enum MethodCodeAttributesGetter implements CodeAttributesGetter { + INSTANCE; + + @Override + public Class codeClass(Method method) { + return method.getDeclaringClass(); + } + + @Override + public String methodName(Method method) { + return method.getName(); + } +} diff --git a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodRequestCodeAttributesGetter.java b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodRequestCodeAttributesGetter.java new file mode 100644 index 000000000000..d52c4fd33b3f --- /dev/null +++ b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/MethodRequestCodeAttributesGetter.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.extensionannotations; + +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; + +enum MethodRequestCodeAttributesGetter implements CodeAttributesGetter { + INSTANCE; + + @Override + public Class codeClass(MethodRequest methodRequest) { + return methodRequest.method().getDeclaringClass(); + } + + @Override + public String methodName(MethodRequest methodRequest) { + return methodRequest.method().getName(); + } +} 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 10e712bc96ff..82e3e3f4f680 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 @@ -12,6 +12,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; import io.opentelemetry.instrumentation.api.util.SpanNames; import java.lang.reflect.Method; import java.util.logging.Logger; @@ -36,6 +37,7 @@ public static Instrumenter instrumenterWithAttributes() { private static Instrumenter createInstrumenter() { return Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, WithSpanSingletons::spanNameFromMethod) + .addAttributesExtractor(CodeAttributesExtractor.create(MethodCodeAttributesGetter.INSTANCE)) .buildInstrumenter(WithSpanSingletons::spanKindFromMethod); } @@ -44,6 +46,8 @@ private static Instrumenter createInstrumenterWithAttribu GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, WithSpanSingletons::spanNameFromMethodRequest) + .addAttributesExtractor( + CodeAttributesExtractor.create(MethodRequestCodeAttributesGetter.INSTANCE)) .addAttributesExtractor( MethodSpanAttributesExtractor.newInstance( MethodRequest::method, diff --git a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy index 14fef17c9ad4..037763ef640a 100644 --- a/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy +++ b/instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy @@ -5,6 +5,7 @@ import io.opentelemetry.extension.annotations.WithSpan import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.test.annotation.TracedWithSpan import net.bytebuddy.ByteBuddy import net.bytebuddy.ClassFileVersion @@ -40,6 +41,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "otel" } } } @@ -57,6 +60,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { name "manualName" hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "namedOtel" } } } @@ -75,6 +80,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind PRODUCER hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "someKind" } } } @@ -93,12 +100,16 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind SERVER hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "server" } } span(1) { name "TracedWithSpan.otel" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "otel" } } } @@ -127,6 +138,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -151,6 +164,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -173,6 +188,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -199,6 +216,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -217,6 +236,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -236,6 +257,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -260,6 +283,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -282,6 +307,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -308,6 +335,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -326,6 +355,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -370,6 +401,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" "GeneratedJava6TestClass" + "$SemanticAttributes.CODE_FUNCTION" "run" } } span(1) { @@ -395,6 +428,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "withSpanAttributes" "implicitName" "foo" "explicitName" "bar" } diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodCodeAttributesGetter.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodCodeAttributesGetter.java new file mode 100644 index 000000000000..9cf2be6ee753 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodCodeAttributesGetter.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.instrumentationannotations; + +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; +import java.lang.reflect.Method; + +enum MethodCodeAttributesGetter implements CodeAttributesGetter { + INSTANCE; + + @Override + public Class codeClass(Method method) { + return method.getDeclaringClass(); + } + + @Override + public String methodName(Method method) { + return method.getName(); + } +} diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodRequestCodeAttributesGetter.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodRequestCodeAttributesGetter.java new file mode 100644 index 000000000000..55f6136e4dbc --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/MethodRequestCodeAttributesGetter.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.instrumentationannotations; + +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; + +enum MethodRequestCodeAttributesGetter implements CodeAttributesGetter { + INSTANCE; + + @Override + public Class codeClass(MethodRequest methodRequest) { + return methodRequest.method().getDeclaringClass(); + } + + @Override + public String methodName(MethodRequest methodRequest) { + return methodRequest.method().getName(); + } +} diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/WithSpanSingletons.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/WithSpanSingletons.java index a5f8b5540c59..3e8291175142 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/WithSpanSingletons.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/WithSpanSingletons.java @@ -12,6 +12,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; import io.opentelemetry.instrumentation.api.util.SpanNames; import java.lang.reflect.Method; import java.util.logging.Logger; @@ -36,6 +37,7 @@ public static Instrumenter instrumenterWithAttributes() { private static Instrumenter createInstrumenter() { return Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, WithSpanSingletons::spanNameFromMethod) + .addAttributesExtractor(CodeAttributesExtractor.create(MethodCodeAttributesGetter.INSTANCE)) .buildInstrumenter(WithSpanSingletons::spanKindFromMethod); } @@ -44,6 +46,8 @@ private static Instrumenter createInstrumenterWithAttribu GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, WithSpanSingletons::spanNameFromMethodRequest) + .addAttributesExtractor( + CodeAttributesExtractor.create(MethodRequestCodeAttributesGetter.INSTANCE)) .addAttributesExtractor( MethodSpanAttributesExtractor.newInstance( MethodRequest::method, diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy index 14fef17c9ad4..037763ef640a 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/groovy/WithSpanInstrumentationTest.groovy @@ -5,6 +5,7 @@ import io.opentelemetry.extension.annotations.WithSpan import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.test.annotation.TracedWithSpan import net.bytebuddy.ByteBuddy import net.bytebuddy.ClassFileVersion @@ -40,6 +41,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "otel" } } } @@ -57,6 +60,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { name "manualName" hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "namedOtel" } } } @@ -75,6 +80,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind PRODUCER hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "someKind" } } } @@ -93,12 +100,16 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind SERVER hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "server" } } span(1) { name "TracedWithSpan.otel" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "otel" } } } @@ -127,6 +138,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -151,6 +164,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -173,6 +188,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -199,6 +216,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -217,6 +236,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completionStage" } } } @@ -236,6 +257,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -260,6 +283,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -282,6 +307,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -308,6 +335,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -326,6 +355,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completableFuture" } } } @@ -370,6 +401,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" "GeneratedJava6TestClass" + "$SemanticAttributes.CODE_FUNCTION" "run" } } span(1) { @@ -395,6 +428,8 @@ class WithSpanInstrumentationTest extends AgentInstrumentationSpecification { kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "withSpanAttributes" "implicitName" "foo" "explicitName" "bar" } diff --git a/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseFluxWithSpanTest.java b/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseFluxWithSpanTest.java index c9b42fcc834a..29efae0ca014 100644 --- a/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseFluxWithSpanTest.java +++ b/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseFluxWithSpanTest.java @@ -5,6 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.reactor; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_FUNCTION; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_NAMESPACE; + import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.javaagent.instrumentation.otelannotations.AbstractWithSpanTest; @@ -58,7 +62,8 @@ void nested() { return Flux.just("Value"); }); - Flux result = newTracedWithSpan().flux(flux); + TracedWithSpan traced = newTracedWithSpan(); + Flux result = traced.flux(flux); StepVerifier.create(result).expectNext("Value").verifyComplete(); @@ -70,7 +75,9 @@ void nested() { span.hasName("TracedWithSpan.flux") .hasKind(SpanKind.INTERNAL) .hasNoParent() - .hasAttributes(Attributes.empty()), + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "flux")), span -> span.hasName("inner-manual") .hasKind(SpanKind.INTERNAL) @@ -80,18 +87,19 @@ void nested() { @Test void nestedFromCurrent() { + TracedWithSpan traced = newTracedWithSpan(); + testing() .runWithSpan( "parent", () -> { Flux result = - newTracedWithSpan() - .flux( - Flux.defer( - () -> { - testing().runWithSpan("inner-manual", () -> {}); - return Flux.just("Value"); - })); + traced.flux( + Flux.defer( + () -> { + testing().runWithSpan("inner-manual", () -> {}); + return Flux.just("Value"); + })); StepVerifier.create(result).expectNext("Value").verifyComplete(); }); @@ -109,7 +117,9 @@ void nestedFromCurrent() { span.hasName("TracedWithSpan.flux") .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(0)) - .hasAttributes(Attributes.empty()), + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "flux")), span -> span.hasName("inner-manual") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseMonoWithSpanTest.java b/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseMonoWithSpanTest.java index dc23d9841ca9..10d4bec55b57 100644 --- a/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseMonoWithSpanTest.java +++ b/instrumentation/reactor/reactor-3.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactor/BaseMonoWithSpanTest.java @@ -5,6 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.reactor; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_FUNCTION; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_NAMESPACE; + import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.javaagent.instrumentation.otelannotations.AbstractWithSpanTest; @@ -58,7 +62,8 @@ void nested() { return Mono.just("Value"); }); - Mono result = newTracedWithSpan().outer(mono); + TracedWithSpan traced = newTracedWithSpan(); + Mono result = traced.outer(mono); StepVerifier.create(result).expectNext("Value").verifyComplete(); @@ -70,12 +75,16 @@ void nested() { span.hasName("TracedWithSpan.outer") .hasKind(SpanKind.INTERNAL) .hasNoParent() - .hasAttributes(Attributes.empty()), + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "outer")), span -> span.hasName("TracedWithSpan.mono") .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(0)) - .hasAttributes(Attributes.empty()), + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "mono")), span -> span.hasName("inner-manual") .hasKind(SpanKind.INTERNAL) @@ -85,18 +94,19 @@ void nested() { @Test void nestedFromCurrent() { + TracedWithSpan traced = newTracedWithSpan(); + testing() .runWithSpan( "parent", () -> { Mono result = - newTracedWithSpan() - .mono( - Mono.defer( - () -> { - testing().runWithSpan("inner-manual", () -> {}); - return Mono.just("Value"); - })); + traced.mono( + Mono.defer( + () -> { + testing().runWithSpan("inner-manual", () -> {}); + return Mono.just("Value"); + })); StepVerifier.create(result).expectNext("Value").verifyComplete(); }); @@ -114,7 +124,9 @@ void nestedFromCurrent() { span.hasName("TracedWithSpan.mono") .hasKind(SpanKind.INTERNAL) .hasParent(trace.getSpan(0)) - .hasAttributes(Attributes.empty()), + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, traced.getClass().getName()), + equalTo(CODE_FUNCTION, "mono")), span -> span.hasName("inner-manual") .hasKind(SpanKind.INTERNAL) diff --git a/instrumentation/rxjava/rxjava-2.0/javaagent/src/test/groovy/RxJava2WithSpanInstrumentationTest.groovy b/instrumentation/rxjava/rxjava-2.0/javaagent/src/test/groovy/RxJava2WithSpanInstrumentationTest.groovy index 5fccfdeedcb8..3a0e2a310e41 100644 --- a/instrumentation/rxjava/rxjava-2.0/javaagent/src/test/groovy/RxJava2WithSpanInstrumentationTest.groovy +++ b/instrumentation/rxjava/rxjava-2.0/javaagent/src/test/groovy/RxJava2WithSpanInstrumentationTest.groovy @@ -5,6 +5,7 @@ import io.opentelemetry.instrumentation.rxjava.v2_0.TracedWithSpan import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Maybe @@ -43,6 +44,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -72,6 +75,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -98,6 +103,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -130,6 +137,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -158,6 +167,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" "rxjava.canceled" true } } @@ -183,6 +194,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -206,6 +219,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -236,6 +251,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -262,6 +279,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -294,6 +313,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -322,6 +343,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" "rxjava.canceled" true } } @@ -347,6 +370,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -377,6 +402,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -403,6 +430,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -435,6 +464,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -463,6 +494,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" "rxjava.canceled" true } } @@ -488,6 +521,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -523,6 +558,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -549,6 +586,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -587,6 +626,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -621,6 +662,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" "rxjava.canceled" true } } @@ -646,6 +689,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -681,6 +726,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -707,6 +754,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -745,6 +794,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -779,6 +830,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" "rxjava.canceled" true } } @@ -805,6 +858,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -841,6 +896,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -868,6 +925,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -907,6 +966,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -942,6 +1003,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" "rxjava.canceled" true } } @@ -972,6 +1035,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" } } } @@ -1004,6 +1069,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" } } } @@ -1032,6 +1099,8 @@ class RxJava2WithSpanInstrumentationTest extends AgentInstrumentationSpecificati kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" "rxjava.canceled" true } } diff --git a/instrumentation/rxjava/rxjava-3-common/testing/src/main/groovy/io/opentelemetry/instrumentation/rxjava/v3/common/AbstractRxJava3WithSpanInstrumentationTest.groovy b/instrumentation/rxjava/rxjava-3-common/testing/src/main/groovy/io/opentelemetry/instrumentation/rxjava/v3/common/AbstractRxJava3WithSpanInstrumentationTest.groovy index 6bf12cc5eb94..3299ffda678b 100644 --- a/instrumentation/rxjava/rxjava-3-common/testing/src/main/groovy/io/opentelemetry/instrumentation/rxjava/v3/common/AbstractRxJava3WithSpanInstrumentationTest.groovy +++ b/instrumentation/rxjava/rxjava-3-common/testing/src/main/groovy/io/opentelemetry/instrumentation/rxjava/v3/common/AbstractRxJava3WithSpanInstrumentationTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.rxjava.v3.common import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.core.Maybe @@ -45,6 +46,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -73,6 +76,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -99,6 +104,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -130,6 +137,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" } } } @@ -157,6 +166,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "completable" "rxjava.canceled" true } } @@ -182,6 +193,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -205,6 +218,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -234,6 +249,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -260,6 +277,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -291,6 +310,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" } } } @@ -318,6 +339,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "maybe" "rxjava.canceled" true } } @@ -343,6 +366,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -372,6 +397,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -398,6 +425,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -429,6 +458,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" } } } @@ -456,6 +487,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "single" "rxjava.canceled" true } } @@ -481,6 +514,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -515,6 +550,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -541,6 +578,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -578,6 +617,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" } } } @@ -611,6 +652,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "observable" "rxjava.canceled" true } } @@ -636,6 +679,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -670,6 +715,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -696,6 +743,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -733,6 +782,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" } } } @@ -766,6 +817,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "flowable" "rxjava.canceled" true } } @@ -792,6 +845,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -827,6 +882,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -854,6 +911,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -892,6 +951,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" } } } @@ -926,6 +987,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "parallelFlowable" "rxjava.canceled" true } } @@ -955,6 +1018,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" } } } @@ -986,6 +1051,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe status ERROR errorEvent(IllegalArgumentException, "Boom") attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" } } } @@ -1013,6 +1080,8 @@ class AbstractRxJava3WithSpanInstrumentationTest extends AgentInstrumentationSpe kind INTERNAL hasNoParent() attributes { + "$SemanticAttributes.CODE_NAMESPACE" TracedWithSpan.name + "$SemanticAttributes.CODE_FUNCTION" "publisher" "rxjava.canceled" true } } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/HttpServletResponseTest.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/HttpServletResponseTest.groovy index d0a3f589910b..cc22e9390a79 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/HttpServletResponseTest.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/HttpServletResponseTest.groovy @@ -5,6 +5,8 @@ import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes + import javax.servlet.http.HttpServlet import spock.lang.Subject @@ -66,18 +68,24 @@ class HttpServletResponseTest extends AgentInstrumentationSpecification { name "TestResponse.sendError" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendError" } } span(2) { name "TestResponse.sendError" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendError" } } span(3) { name "TestResponse.sendRedirect" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendRedirect" } } } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy index cf22b521b103..e3f592ca4175 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy @@ -10,6 +10,7 @@ import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes +import org.eclipse.jetty.server.Response import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.servlet.ServletContextHandler @@ -111,11 +112,14 @@ class JettyServlet2Test extends HttpServerTest implements AgentTestTrait @Override void responseSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) { + def responseMethod = endpoint == REDIRECT ? "sendRedirect" : "sendError" trace.span(index) { - name endpoint == REDIRECT ? "Response.sendRedirect" : "Response.sendError" + name "Response.$responseMethod" kind INTERNAL childOf((SpanData) parent) attributes { + "$SemanticAttributes.CODE_NAMESPACE" Response.name + "$SemanticAttributes.CODE_FUNCTION" responseMethod } } } diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/HttpServletResponseTest.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/HttpServletResponseTest.groovy index 1ee25a12cf87..163937448759 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/HttpServletResponseTest.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/HttpServletResponseTest.groovy @@ -5,6 +5,8 @@ import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes + import javax.servlet.http.HttpServlet import spock.lang.Subject @@ -66,18 +68,24 @@ class HttpServletResponseTest extends AgentInstrumentationSpecification { name "TestResponse.sendError" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendError" } } span(2) { name "TestResponse.sendError" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendError" } } span(3) { name "TestResponse.sendRedirect" childOf span(0) attributes { + "$SemanticAttributes.CODE_NAMESPACE" TestResponse.name + "$SemanticAttributes.CODE_FUNCTION" "sendRedirect" } } } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/common/response/ResponseInstrumenterFactory.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/common/response/ResponseInstrumenterFactory.java index 77a8c156d677..699ffc70794d 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/common/response/ResponseInstrumenterFactory.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/common/response/ResponseInstrumenterFactory.java @@ -7,14 +7,21 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; -import io.opentelemetry.instrumentation.api.util.SpanNames; public final class ResponseInstrumenterFactory { public static Instrumenter createInstrumenter(String instrumentationName) { + CodeAttributesGetter codeAttributesGetter = + ClassAndMethod.codeAttributesGetter(); return Instrumenter.builder( - GlobalOpenTelemetry.get(), instrumentationName, SpanNames::fromMethod) + GlobalOpenTelemetry.get(), + instrumentationName, + CodeSpanNameExtractor.create(codeAttributesGetter)) + .addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter)) .buildInstrumenter(); } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/JointPointCodeAttributesExtractor.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/JointPointCodeAttributesExtractor.java new file mode 100644 index 000000000000..3c83bbd3cd11 --- /dev/null +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/JointPointCodeAttributesExtractor.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.autoconfigure.aspects; + +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; + +enum JointPointCodeAttributesExtractor implements CodeAttributesGetter { + INSTANCE; + + @Override + public Class codeClass(JoinPointRequest joinPointRequest) { + return joinPointRequest.method().getDeclaringClass(); + } + + @Override + public String methodName(JoinPointRequest joinPointRequest) { + return joinPointRequest.method().getName(); + } +} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java index 359c443a2663..56a597d01add 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java @@ -14,6 +14,7 @@ import io.opentelemetry.instrumentation.api.annotation.support.ParameterAttributeNamesExtractor; import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndSupport; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; import io.opentelemetry.instrumentation.api.util.SpanNames; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; @@ -44,6 +45,8 @@ public WithSpanAspect( instrumenter = Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, WithSpanAspect::spanName) + .addAttributesExtractor( + CodeAttributesExtractor.create(JointPointCodeAttributesExtractor.INSTANCE)) .addAttributesExtractor( MethodSpanAttributesExtractor.newInstance( JoinPointRequest::method, diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTest.java index cf7a9efd94c2..314c9e39edd1 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspectTest.java @@ -5,13 +5,15 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.aspects; +import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.TracesAssert.assertThat; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_FUNCTION; +import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.CODE_NAMESPACE; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; import io.opentelemetry.extension.annotations.SpanAttribute; import io.opentelemetry.extension.annotations.WithSpan; import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; @@ -118,9 +120,10 @@ void withSpanWithDefaults() throws Throwable { span -> span.hasName("WithSpanTester.testWithSpan") .hasKind(INTERNAL) - // otel SDK assertions need some work before we can comfortably use - // them in this project... - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testWithSpan")))); } @Test @@ -140,7 +143,10 @@ void withSpanName() throws Throwable { span -> span.hasName("greatestSpanEver") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testWithSpanWithValue")))); } @Test @@ -158,7 +164,10 @@ void withSpanError() throws Throwable { span -> span.hasName("WithSpanTester.testWithSpanWithException") .hasKind(INTERNAL) - .hasStatus(StatusData.error()))); + .hasStatus(StatusData.error()) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testWithSpanWithException")))); } @Test @@ -178,7 +187,10 @@ void withSpanKind() throws Throwable { span -> span.hasName("WithSpanTester.testWithClientSpan") .hasKind(CLIENT) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testWithClientSpan")))); } @Test @@ -198,12 +210,13 @@ void withSpanAttributes() throws Throwable { span -> span.hasName("WithSpanTester.withSpanAttributes") .hasKind(INTERNAL) - .hasAttributes( - Attributes.of( - AttributeKey.stringKey("discoveredName"), "foo", - AttributeKey.stringKey("implicitName"), "bar", - AttributeKey.stringKey("explicitName"), "baz")) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "withSpanAttributes"), + equalTo(stringKey("discoveredName"), "foo"), + equalTo(stringKey("implicitName"), "bar"), + equalTo(stringKey("explicitName"), "baz")))); } @Nested @@ -239,7 +252,10 @@ void onComplete() throws Throwable { span -> span.hasName("WithSpanTester.testAsyncCompletionStage") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletionStage")))); } @Test @@ -272,7 +288,10 @@ void onCompleteExceptionally() throws Throwable { span.hasName("WithSpanTester.testAsyncCompletionStage") .hasKind(INTERNAL) .hasStatus(StatusData.error()) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletionStage")))); } @Test @@ -291,7 +310,10 @@ void onIncompatibleReturnValue() throws Throwable { span -> span.hasName("WithSpanTester.testAsyncCompletionStage") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletionStage")))); } } @@ -328,7 +350,10 @@ void onComplete() throws Throwable { span -> span.hasName("WithSpanTester.testAsyncCompletableFuture") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletableFuture")))); } @Test @@ -361,7 +386,10 @@ void onCompleteExceptionally() throws Throwable { span.hasName("WithSpanTester.testAsyncCompletableFuture") .hasKind(INTERNAL) .hasStatus(StatusData.error()) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletableFuture")))); } @Test @@ -382,7 +410,10 @@ void onCompletedFuture() throws Throwable { span -> span.hasName("WithSpanTester.testAsyncCompletableFuture") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletableFuture")))); } @Test @@ -405,7 +436,10 @@ void onFailedFuture() throws Throwable { span.hasName("WithSpanTester.testAsyncCompletableFuture") .hasKind(INTERNAL) .hasStatus(StatusData.error()) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletableFuture")))); } @Test @@ -424,7 +458,10 @@ void onIncompatibleReturnValue() throws Throwable { span -> span.hasName("WithSpanTester.testAsyncCompletableFuture") .hasKind(INTERNAL) - .hasParentSpanId(traces.get(0).get(0).getSpanId()))); + .hasParent(trace.getSpan(0)) + .hasAttributesSatisfyingExactly( + equalTo(CODE_NAMESPACE, WithSpanTester.class.getName()), + equalTo(CODE_FUNCTION, "testAsyncCompletableFuture")))); } } } diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java index c1050f05fa01..0bacec8ab4cd 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java @@ -7,15 +7,27 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.code.CodeSpanNameExtractor; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; -import io.opentelemetry.instrumentation.api.util.SpanNames; public final class SpringDataSingletons { - private static final Instrumenter INSTRUMENTER = - Instrumenter.builder( - GlobalOpenTelemetry.get(), "io.opentelemetry.spring-data-1.8", SpanNames::fromMethod) - .buildInstrumenter(); + private static final Instrumenter INSTRUMENTER; + + static { + CodeAttributesGetter codeAttributesGetter = + ClassAndMethod.codeAttributesGetter(); + + INSTRUMENTER = + Instrumenter.builder( + GlobalOpenTelemetry.get(), + "io.opentelemetry.spring-data-1.8", + CodeSpanNameExtractor.create(codeAttributesGetter)) + .addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter)) + .buildInstrumenter(); + } public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/test/groovy/SpringJpaTest.groovy b/instrumentation/spring/spring-data-1.8/javaagent/src/test/groovy/SpringJpaTest.groovy index 784e2dd309d5..c82362c85720 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/test/groovy/SpringJpaTest.groovy +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/test/groovy/SpringJpaTest.groovy @@ -63,6 +63,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.findAll" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findAll" } } span(1) { // select @@ -95,6 +97,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.save" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "save" } } def offset = 0 @@ -144,6 +148,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.save" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "save" } } span(1) { // select @@ -188,6 +194,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.findByLastName" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findByLastName" } } span(1) { // select @@ -218,6 +226,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.delete" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "delete" } } span(1) { // select @@ -271,6 +281,8 @@ class SpringJpaTest extends AgentInstrumentationSpecification { name "JpaCustomerRepository.findSpecialCustomers" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" JpaCustomerRepository.name + "$SemanticAttributes.CODE_FUNCTION" "findSpecialCustomers" } } span(1) { // select diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy index f5d191e10777..5cc3e707bc98 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy @@ -11,12 +11,14 @@ import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import io.opentelemetry.testing.internal.armeria.common.HttpData import io.opentelemetry.testing.internal.armeria.common.MediaType import io.opentelemetry.testing.internal.armeria.common.QueryParams import org.springframework.boot.SpringApplication import org.springframework.context.ConfigurableApplicationContext +import org.springframework.security.web.util.OnCommittedResponseWrapper import org.springframework.web.servlet.view.RedirectView import static io.opentelemetry.api.trace.SpanKind.INTERNAL @@ -154,11 +156,13 @@ class SpringBootBasedTest extends HttpServerTest @Override void responseSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) { - def responseSpanName = endpoint == NOT_FOUND ? "OnCommittedResponseWrapper.sendError" : "OnCommittedResponseWrapper.sendRedirect" + def methodName = endpoint == NOT_FOUND ? "sendError" : "sendRedirect" trace.span(index) { - name responseSpanName + name "OnCommittedResponseWrapper.$methodName" kind INTERNAL attributes { + "$SemanticAttributes.CODE_NAMESPACE" OnCommittedResponseWrapper.name + "$SemanticAttributes.CODE_FUNCTION" methodName } } }