diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseConfig.java b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseConfig.java new file mode 100644 index 000000000000..4cf0454ccf87 --- /dev/null +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.couchbase.v2_6; + +import io.opentelemetry.instrumentation.api.config.Config; + +public final class CouchbaseConfig { + + public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.couchbase.experimental-span-attributes", false); + + private CouchbaseConfig() {} +} diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseCoreInstrumentation.java b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseCoreInstrumentation.java index a396e3c23ca5..072511e65e2c 100644 --- a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseCoreInstrumentation.java +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseCoreInstrumentation.java @@ -57,8 +57,9 @@ public static void addOperationIdToSpan(@Advice.Argument(0) CouchbaseRequest req if (span == null) { span = parentSpan; contextStore.put(request, span); - - span.setAttribute("couchbase.operation_id", request.operationId()); + if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("couchbase.operation_id", request.operationId()); + } } } } diff --git a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java index d96e8f8bc036..c083506d0aab 100644 --- a/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java +++ b/instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseNetworkInstrumentation.java @@ -79,7 +79,9 @@ public static void addNetworkTagsToSpan( } } - span.setAttribute("couchbase.local.address", localSocket); + if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("couchbase.local.address", localSocket); + } } } } diff --git a/instrumentation/grpc-1.5/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_5/server/TracingServerInterceptor.java b/instrumentation/grpc-1.5/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_5/server/TracingServerInterceptor.java index 4c2901c58d86..ac2c47a1bb8a 100644 --- a/instrumentation/grpc-1.5/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_5/server/TracingServerInterceptor.java +++ b/instrumentation/grpc-1.5/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_5/server/TracingServerInterceptor.java @@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.grpc.v1_5.common.GrpcHelper; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; @@ -27,6 +28,10 @@ public class TracingServerInterceptor implements ServerInterceptor { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.grpc.experimental-span-attributes", false); + public static ServerInterceptor newInterceptor() { return newInterceptor(new GrpcServerTracer()); } @@ -139,7 +144,9 @@ public void onHalfClose() { public void onCancel() { try (Scope ignored = span.makeCurrent()) { delegate().onCancel(); - span.setAttribute("grpc.canceled", true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("grpc.canceled", true); + } } catch (Throwable e) { tracer.endExceptionally(span, e); throw e; diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java index 37e67dd32459..ce84d24e9a2f 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java @@ -95,7 +95,9 @@ public static void stopSpan(@Advice.This AsyncResponse asyncResponse) { Span span = contextStore.get(asyncResponse); if (span != null) { contextStore.put(asyncResponse, null); - span.setAttribute("jaxrs.canceled", true); + if (JaxrsConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("jaxrs.canceled", true); + } tracer().end(span); } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsConfig.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsConfig.java new file mode 100644 index 000000000000..1c0c06c2ea91 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; + +import io.opentelemetry.instrumentation.api.config.Config; + +public final class JaxrsConfig { + + public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.jaxrs.experimental-span-attributes", false); + + private JaxrsConfig() {} +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/jaxrs-2.0-cxf-3.2-javaagent.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/jaxrs-2.0-cxf-3.2-javaagent.gradle index 0ac0ebf61099..c718c026fe88 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/jaxrs-2.0-cxf-3.2-javaagent.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/jaxrs-2.0-cxf-3.2-javaagent.gradle @@ -24,4 +24,9 @@ dependencies { testLibrary group: 'org.apache.cxf', name: 'cxf-rt-transports-http-jetty', version: '3.2.0' testLibrary group: 'org.apache.cxf', name: 'cxf-rt-ws-policy', version: '3.2.0' -} \ No newline at end of file +} + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true" +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/jaxrs-2.0-jersey-2.0-javaagent.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/jaxrs-2.0-jersey-2.0-javaagent.gradle index 376524bc21d4..ff4cb569cb85 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/jaxrs-2.0-jersey-2.0-javaagent.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/jaxrs-2.0-jersey-2.0-javaagent.gradle @@ -30,3 +30,8 @@ dependencies { test { systemProperty 'testLatestDeps', testLatestDeps } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true" +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/jaxrs-2.0-resteasy-3.0-javaagent.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/jaxrs-2.0-resteasy-3.0-javaagent.gradle index 8d0fce6da8cf..3752d193d57f 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/jaxrs-2.0-resteasy-3.0-javaagent.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/javaagent/jaxrs-2.0-resteasy-3.0-javaagent.gradle @@ -45,3 +45,8 @@ dependencies { test { systemProperty 'testLatestDeps', testLatestDeps } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true" +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/jaxrs-2.0-resteasy-3.1-javaagent.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/jaxrs-2.0-resteasy-3.1-javaagent.gradle index 4c8fc4595131..81c67bd2c5f5 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/jaxrs-2.0-resteasy-3.1-javaagent.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/javaagent/jaxrs-2.0-resteasy-3.1-javaagent.gradle @@ -49,3 +49,8 @@ if (findProperty('testLatestDeps')) { testImplementation.exclude group: 'org.jboss.resteasy', module: 'resteasy-jaxrs' } } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true" +} diff --git a/instrumentation/jsp-2.3/javaagent/jsp-2.3-javaagent.gradle b/instrumentation/jsp-2.3/javaagent/jsp-2.3-javaagent.gradle index fac4d1be91fd..d7d39bf0900e 100644 --- a/instrumentation/jsp-2.3/javaagent/jsp-2.3-javaagent.gradle +++ b/instrumentation/jsp-2.3/javaagent/jsp-2.3-javaagent.gradle @@ -40,4 +40,7 @@ tasks.withType(Test) { // JarScanFilter did not exist in the tomcat 7 api jvmArgs '-Dorg.apache.catalina.startup.ContextConfig.jarsToSkip=*' jvmArgs '-Dorg.apache.catalina.startup.TldConfig.jarsToSkip=*' + + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.jsp.experimental-span-attributes=true" } diff --git a/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspTracer.java b/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspTracer.java index 6ad98a134037..ee7c7c12f3c3 100644 --- a/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspTracer.java +++ b/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspTracer.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import java.net.URI; import java.net.URISyntaxException; @@ -18,6 +19,11 @@ import org.slf4j.LoggerFactory; public class JspTracer extends BaseTracer { + + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.jsp.experimental-span-attributes", false); + private static final JspTracer TRACER = new JspTracer(); public static JspTracer tracer() { @@ -31,7 +37,7 @@ public String spanNameOnCompile(JspCompilationContext jspCompilationContext) { } public void onCompile(Context context, JspCompilationContext jspCompilationContext) { - if (jspCompilationContext != null) { + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES && jspCompilationContext != null) { Span span = Span.fromContext(context); Compiler compiler = jspCompilationContext.getCompiler(); if (compiler != null) { @@ -52,6 +58,9 @@ public String spanNameOnRender(HttpServletRequest req) { } public void onRender(Context context, HttpServletRequest req) { + if (!CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + return; + } Span span = Span.fromContext(context); Object forwardOrigin = req.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH); diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientTracer.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientTracer.java index d0d1a43738c8..3d6e29840962 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientTracer.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientTracer.java @@ -9,14 +9,22 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapSetter; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer; import java.net.URI; import okhttp3.Request; import okhttp3.Response; public class KubernetesClientTracer extends HttpClientTracer { + + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.kubernetes-client.experimental-span-attributes", false); + private static final KubernetesClientTracer TRACER = new KubernetesClientTracer(); public static KubernetesClientTracer tracer() { @@ -29,14 +37,14 @@ public static KubernetesClientTracer tracer() { */ public Context startSpan(Context parentContext, Request request) { KubernetesRequestDigest digest = KubernetesRequestDigest.parse(request); - Span span = - tracer - .spanBuilder(digest.toString()) - .setSpanKind(CLIENT) - .setParent(parentContext) - .setAttribute("namespace", digest.getResourceMeta().getNamespace()) - .setAttribute("name", digest.getResourceMeta().getName()) - .startSpan(); + SpanBuilder spanBuilder = + tracer.spanBuilder(digest.toString()).setSpanKind(CLIENT).setParent(parentContext); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + spanBuilder + .setAttribute("kubernetes-client.namespace", digest.getResourceMeta().getNamespace()) + .setAttribute("kubernetes-client.name", digest.getResourceMeta().getName()); + } + Span span = spanBuilder.startSpan(); Context context = withClientSpan(parentContext, span); GlobalOpenTelemetry.getPropagators() .getTextMapPropagator() diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/InstrumentationPoints.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/InstrumentationPoints.java index ad270b4289bc..1dc42f09f40b 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/InstrumentationPoints.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/InstrumentationPoints.java @@ -16,12 +16,17 @@ import com.lambdaworks.redis.protocol.RedisCommand; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import java.util.EnumSet; import java.util.Set; import java.util.concurrent.CancellationException; public final class InstrumentationPoints { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false); + private static final Set NON_INSTRUMENTING_COMMANDS = EnumSet.of(SHUTDOWN, DEBUG); public static void afterCommand( @@ -37,8 +42,10 @@ public static void afterCommand( if (ex == null) { tracer().end(context); } else if (ex instanceof CancellationException) { - Span span = Span.fromContext(context); - span.setAttribute("lettuce.command.cancelled", true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); + span.setAttribute("lettuce.command.cancelled", true); + } tracer().end(context); } else { tracer().endExceptionally(context, ex); diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncBiFunction.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncBiFunction.java index 67562c0befdf..3edd2f2d8519 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncBiFunction.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncBiFunction.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import java.util.concurrent.CancellationException; import java.util.function.BiFunction; @@ -24,6 +25,10 @@ public class LettuceAsyncBiFunction implements BiFunction { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false); + private final Context context; public LettuceAsyncBiFunction(Context context) { @@ -33,8 +38,10 @@ public LettuceAsyncBiFunction(Context context) { @Override public R apply(T t, Throwable throwable) { if (throwable instanceof CancellationException) { - Span span = Span.fromContext(context); - span.setAttribute("lettuce.command.cancelled", true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); + span.setAttribute("lettuce.command.cancelled", true); + } tracer().end(context); } else { tracer().endExceptionally(context, throwable); diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceFluxTerminationRunnable.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceFluxTerminationRunnable.java index f978534098cf..658b7062566b 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceFluxTerminationRunnable.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/rx/LettuceFluxTerminationRunnable.java @@ -10,6 +10,7 @@ import io.lettuce.core.protocol.RedisCommand; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import java.util.function.Consumer; import org.reactivestreams.Subscription; import org.slf4j.LoggerFactory; @@ -19,6 +20,10 @@ public class LettuceFluxTerminationRunnable implements Consumer>, Runnable { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false); + private Context context; private int numResults; private final FluxOnSubscribeConsumer onSubscribeConsumer; @@ -34,9 +39,11 @@ public FluxOnSubscribeConsumer getOnSubscribeConsumer() { private void finishSpan(boolean isCommandCancelled, Throwable throwable) { if (context != null) { Span span = Span.fromContext(context); - span.setAttribute("lettuce.command.results.count", numResults); - if (isCommandCancelled) { - span.setAttribute("lettuce.command.cancelled", true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("lettuce.command.results.count", numResults); + if (isCommandCancelled) { + span.setAttribute("lettuce.command.cancelled", true); + } } if (throwable == null) { tracer().end(span); diff --git a/instrumentation/rabbitmq-2.7/javaagent/rabbitmq-2.7-javaagent.gradle b/instrumentation/rabbitmq-2.7/javaagent/rabbitmq-2.7-javaagent.gradle index b1a6708e30e5..034eb1ae4d65 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/rabbitmq-2.7-javaagent.gradle +++ b/instrumentation/rabbitmq-2.7/javaagent/rabbitmq-2.7-javaagent.gradle @@ -22,3 +22,8 @@ configurations.testRuntime { force group: 'com.rabbitmq', name: 'amqp-client', version: '2.7.0' } } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.rabbitmq.experimental-span-attributes=true" +} diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitTracer.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitTracer.java index 03b5fbe1bc13..da59e313367f 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitTracer.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitTracer.java @@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanBuilder; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -27,6 +28,10 @@ public class RabbitTracer extends BaseTracer { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.rabbitmq.experimental-span-attributes", false); + private static final RabbitTracer TRACER = new RabbitTracer(); public static RabbitTracer tracer() { @@ -60,8 +65,9 @@ public Span startGetSpan( spanBuilder.setAttribute( SemanticAttributes.MESSAGING_DESTINATION, normalizeExchangeName(response.getEnvelope().getExchange())); - spanBuilder.setAttribute( - "messaging.rabbitmq.routing_key", response.getEnvelope().getRoutingKey()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + spanBuilder.setAttribute("rabbitmq.routing_key", response.getEnvelope().getRoutingKey()); + } spanBuilder.setAttribute( SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, (long) response.getBody().length); @@ -92,7 +98,7 @@ public Span startDeliverySpan( span.setAttribute( SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, (long) body.length); } - if (properties.getTimestamp() != null) { + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES && properties.getTimestamp() != null) { // this will be set if the sender sets the timestamp, // or if a plugin is installed on the rabbitmq broker long produceTime = properties.getTimestamp().getTime(); @@ -111,9 +117,11 @@ public void onPublish(Span span, String exchange, String routingKey) { ? "" : routingKey.startsWith("amq.gen-") ? "" : routingKey; span.updateName(exchangeName + " -> " + routing + " send"); - span.setAttribute("rabbitmq.command", "basic.publish"); - if (routingKey != null && !routingKey.isEmpty()) { - span.setAttribute("messaging.rabbitmq.routing_key", routingKey); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("rabbitmq.command", "basic.publish"); + if (routingKey != null && !routingKey.isEmpty()) { + span.setAttribute("rabbitmq.routing_key", routingKey); + } } } @@ -122,8 +130,10 @@ public String spanNameOnGet(String queue) { } public void onGet(SpanBuilder span, String queue) { - span.setAttribute("rabbitmq.command", "basic.get"); - span.setAttribute("rabbitmq.queue", queue); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("rabbitmq.command", "basic.get"); + span.setAttribute("rabbitmq.queue", queue); + } } public String spanNameOnDeliver(String queue) { @@ -137,14 +147,18 @@ public String spanNameOnDeliver(String queue) { } public void onDeliver(Span span, Envelope envelope) { - span.setAttribute("rabbitmq.command", "basic.deliver"); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("rabbitmq.command", "basic.deliver"); + } if (envelope != null) { String exchange = envelope.getExchange(); span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION, normalizeExchangeName(exchange)); - String routingKey = envelope.getRoutingKey(); - if (routingKey != null && !routingKey.isEmpty()) { - span.setAttribute("messaging.rabbitmq.routing_key", routingKey); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + String routingKey = envelope.getRoutingKey(); + if (routingKey != null && !routingKey.isEmpty()) { + span.setAttribute("rabbitmq.routing_key", routingKey); + } } } } @@ -159,7 +173,9 @@ public void onCommand(Span span, Command command) { if (!name.equals("basic.publish")) { span.updateName(name); } - span.setAttribute("rabbitmq.command", name); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("rabbitmq.command", name); + } } @Override diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMQTest.groovy b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMQTest.groovy index d7547f2ae928..26864fd95241 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMQTest.groovy +++ b/instrumentation/rabbitmq-2.7/javaagent/src/test/groovy/RabbitMQTest.groovy @@ -364,7 +364,7 @@ class RabbitMQTest extends AgentInstrumentationSpecification { "${SemanticAttributes.MESSAGING_DESTINATION.key}" exchange "${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue" //TODO add to SemanticAttributes - "messaging.rabbitmq.routing_key" { it == null || it == routingKey || it.startsWith("amq.gen-") } + "rabbitmq.routing_key" { it == null || it == routingKey || it.startsWith("amq.gen-") } if (operation != null && operation != "send") { "${SemanticAttributes.MESSAGING_OPERATION.key}" operation } diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3HttpServerTracer.java b/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3HttpServerTracer.java index 54a757b99762..73146a37b02e 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3HttpServerTracer.java +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v3_0/Servlet3HttpServerTracer.java @@ -8,12 +8,17 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.servlet.ServletHttpServerTracer; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Servlet3HttpServerTracer extends ServletHttpServerTracer { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.servlet.experimental-span-attributes", false); + private static final Servlet3HttpServerTracer TRACER = new Servlet3HttpServerTracer(); public static Servlet3HttpServerTracer tracer() { @@ -43,7 +48,9 @@ protected boolean isResponseCommitted(HttpServletResponse response) { public void onTimeout(Context context, long timeout) { Span span = Span.fromContext(context); span.setStatus(StatusCode.ERROR); - span.setAttribute("servlet.timeout", timeout); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("servlet.timeout", timeout); + } span.end(); } diff --git a/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/CompletionListener.java b/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/CompletionListener.java index f99ebdce39b0..789975ed3fa2 100644 --- a/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/CompletionListener.java +++ b/instrumentation/spymemcached-2.12/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spymemcached/CompletionListener.java @@ -9,16 +9,22 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import net.spy.memcached.MemcachedConnection; public abstract class CompletionListener { - static final String DB_COMMAND_CANCELLED = "lettuce.command.cancelled"; - static final String MEMCACHED_RESULT = "memcached.result"; - static final String HIT = "hit"; - static final String MISS = "miss"; + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.spymemcached.experimental-span-attributes", false); + + private static final String DB_COMMAND_CANCELLED = "spymemcached.command.cancelled"; + private static final String MEMCACHED_RESULT = "spymemcached.result"; + private static final String HIT = "hit"; + private static final String MISS = "miss"; private final Context context; @@ -32,12 +38,16 @@ protected void closeAsyncSpan(T future) { try { processResult(span, future); } catch (CancellationException e) { - span.setAttribute(DB_COMMAND_CANCELLED, true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute(DB_COMMAND_CANCELLED, true); + } } catch (ExecutionException e) { if (e.getCause() instanceof CancellationException) { // Looks like underlying OperationFuture wraps CancellationException into // ExecutionException - span.setAttribute(DB_COMMAND_CANCELLED, true); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute(DB_COMMAND_CANCELLED, true); + } } else { tracer().endExceptionally(span, e); } @@ -61,6 +71,8 @@ protected abstract void processResult(Span span, T future) throws ExecutionException, InterruptedException; protected void setResultTag(Span span, boolean hit) { - span.setAttribute(MEMCACHED_RESULT, hit ? HIT : MISS); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute(MEMCACHED_RESULT, hit ? HIT : MISS); + } } } diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java index 8198d16f1ece..4e251c05f1d6 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioTracer.java @@ -12,6 +12,7 @@ import com.twilio.rest.api.v2010.account.Message; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import java.lang.reflect.Method; import java.util.concurrent.TimeUnit; @@ -20,6 +21,10 @@ public class TwilioTracer extends BaseTracer { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.twilio.experimental-span-attributes", false); + private static final Logger log = LoggerFactory.getLogger(TwilioTracer.class); public static final TwilioTracer TRACER = new TwilioTracer(); @@ -67,36 +72,38 @@ public void end(Context context, Object result) { return; } - // Provide helpful metadata for some of the more common response types - span.setAttribute("twilio.type", result.getClass().getCanonicalName()); - - // Instrument the most popular resource types directly - if (result instanceof Message) { - Message message = (Message) result; - span.setAttribute("twilio.account", message.getAccountSid()); - span.setAttribute("twilio.sid", message.getSid()); - Message.Status status = message.getStatus(); - if (status != null) { - span.setAttribute("twilio.status", status.toString()); - } - } else if (result instanceof Call) { - Call call = (Call) result; - span.setAttribute("twilio.account", call.getAccountSid()); - span.setAttribute("twilio.sid", call.getSid()); - span.setAttribute("twilio.parentSid", call.getParentCallSid()); - Call.Status status = call.getStatus(); - if (status != null) { - span.setAttribute("twilio.status", status.toString()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + // Provide helpful metadata for some of the more common response types + span.setAttribute("twilio.type", result.getClass().getCanonicalName()); + + // Instrument the most popular resource types directly + if (result instanceof Message) { + Message message = (Message) result; + span.setAttribute("twilio.account", message.getAccountSid()); + span.setAttribute("twilio.sid", message.getSid()); + Message.Status status = message.getStatus(); + if (status != null) { + span.setAttribute("twilio.status", status.toString()); + } + } else if (result instanceof Call) { + Call call = (Call) result; + span.setAttribute("twilio.account", call.getAccountSid()); + span.setAttribute("twilio.sid", call.getSid()); + span.setAttribute("twilio.parentSid", call.getParentCallSid()); + Call.Status status = call.getStatus(); + if (status != null) { + span.setAttribute("twilio.status", status.toString()); + } + } else { + // Use reflection to gather insight from other types; note that Twilio requests take close + // to + // 1 second, so the added hit from reflection here is relatively minimal in the grand scheme + // of things + setTagIfPresent(span, result, "twilio.sid", "getSid"); + setTagIfPresent(span, result, "twilio.account", "getAccountSid"); + setTagIfPresent(span, result, "twilio.status", "getStatus"); } - } else { - // Use reflection to gather insight from other types; note that Twilio requests take close to - // 1 second, so the added hit from reflection here is relatively minimal in the grand scheme - // of things - setTagIfPresent(span, result, "twilio.sid", "getSid"); - setTagIfPresent(span, result, "twilio.account", "getAccountSid"); - setTagIfPresent(span, result, "twilio.status", "getStatus"); } - super.end(span); } diff --git a/instrumentation/twilio-6.6/javaagent/twilio-6.6-javaagent.gradle b/instrumentation/twilio-6.6/javaagent/twilio-6.6-javaagent.gradle index d5e067d2bd98..f52b3982f0e8 100644 --- a/instrumentation/twilio-6.6/javaagent/twilio-6.6-javaagent.gradle +++ b/instrumentation/twilio-6.6/javaagent/twilio-6.6-javaagent.gradle @@ -17,3 +17,8 @@ dependencies { latestDepTestLibrary group: 'com.twilio.sdk', name: 'twilio', version: '7.+' } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.twilio.experimental-span-attributes=true" +}