diff --git a/docs/config/common.md b/docs/config/common.md index d2b768ec4462..c56cbc7428e6 100644 --- a/docs/config/common.md +++ b/docs/config/common.md @@ -53,8 +53,8 @@ These configuration options are supported by all HTTP client and server instrume ## Capturing servlet request parameters You can configure the agent to capture predefined HTTP request parameter as span attributes for -requests that are handled by Servlet API. -Use the following property to define which servlet request parameters you want to capture: +requests that are handled by Servlet API. Use the following property to define which servlet request +parameters you want to capture: | System property | Environment variable | Description | | ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ----------- | @@ -62,3 +62,18 @@ Use the following property to define which servlet request parameters you want t > **Note**: The property/environment variable names listed in the table are still experimental, > and thus are subject to change. + +## Capturing consumer message receive telemetry in messaging instrumentations + +You can configure the agent to capture the consumer message receive telemetry in messaging +instrumentation. Use the following property to enable it: + +| System property | Environment variable | Description | +| ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------- | +| `otel.instrumentation.messaging.experimental.receive-telemetry.enabled` | `OTEL_INSTRUMENTATION_MESSAGING_EXPERIMENTAL_RECEIVE_TELEMETRY_ENABLED` | Enables the consumer message receive telemetry. The default value is `false`. + +Note that this will cause the consumer side to start a new trace, with only a span link connecting +it to the producer trace. + +> **Note**: The property/environment variable names listed in the table are still experimental, +> and thus are subject to change. diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/ExperimentalConfig.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/ExperimentalConfig.java index 4b3c21089ea2..6c70542ce84b 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/ExperimentalConfig.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/ExperimentalConfig.java @@ -32,8 +32,13 @@ public boolean suppressViewSpans() { return config.getBoolean("otel.instrumentation.common.experimental.suppress-view-spans", false); } - public boolean suppressMessagingReceiveSpans() { + public boolean messagingReceiveInstrumentationEnabled() { + // TODO: remove that `suppress...` flag after 1.13 release + boolean receiveSpansSuppressed = + config.getBoolean( + "otel.instrumentation.common.experimental.suppress-messaging-receive-spans", true); return config.getBoolean( - "otel.instrumentation.common.experimental.suppress-messaging-receive-spans", false); + "otel.instrumentation.messaging.experimental.receive-telemetry.enabled", + !receiveSpansSuppressed); } } diff --git a/instrumentation/jms-1.1/javaagent/build.gradle.kts b/instrumentation/jms-1.1/javaagent/build.gradle.kts index 4ac36d858955..14f6248413fd 100644 --- a/instrumentation/jms-1.1/javaagent/build.gradle.kts +++ b/instrumentation/jms-1.1/javaagent/build.gradle.kts @@ -30,7 +30,6 @@ tasks { isFailOnNoMatchingTests = false } include("**/SpringListenerJms1SuppressReceiveSpansTest.*") - jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true") } val jms2Test by existing(Test::class) { @@ -39,13 +38,13 @@ tasks { // running a single test in the default test set will fail isFailOnNoMatchingTests = false } + jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true") } val jms2TestReceiveSpansDisabled by existing(Test::class) { filter { isFailOnNoMatchingTests = false } - jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true") } test { @@ -57,6 +56,7 @@ tasks { excludeTestsMatching("SpringListenerJms1SuppressReceiveSpansTest") isFailOnNoMatchingTests = false } + jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true") } } diff --git a/instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsSingletons.java b/instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsSingletons.java index 0bbe86719381..eec886b88a69 100644 --- a/instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsSingletons.java +++ b/instrumentation/jms-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jms/JmsSingletons.java @@ -46,7 +46,7 @@ private static Instrumenter buildConsumerInstrumen GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) .addAttributesExtractor(attributesExtractor) .setTimeExtractor(new JmsMessageTimeExtractor()) - .setDisabled(ExperimentalConfig.get().suppressMessagingReceiveSpans()) + .setDisabled(!ExperimentalConfig.get().messagingReceiveInstrumentationEnabled()) .newInstrumenter(SpanKindExtractor.alwaysConsumer()); } diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/build.gradle.kts b/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/build.gradle.kts index 42cfcc1e489b..080543473abe 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/build.gradle.kts +++ b/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/build.gradle.kts @@ -47,7 +47,6 @@ tasks { isFailOnNoMatchingTests = false } include("**/KafkaClientSuppressReceiveSpansTest.*") - jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true") } test { @@ -58,5 +57,6 @@ tasks { excludeTestsMatching("KafkaClientSuppressReceiveSpansTest") isFailOnNoMatchingTests = false } + jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true") } } diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/KafkaClientPropagationDisabledTest.groovy b/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/KafkaClientPropagationDisabledTest.groovy index 7ccf068308bc..9d13ab21bf7b 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/KafkaClientPropagationDisabledTest.groovy +++ b/instrumentation/kafka/kafka-clients/kafka-clients-0.11/javaagent/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/KafkaClientPropagationDisabledTest.groovy @@ -60,22 +60,10 @@ class KafkaClientPropagationDisabledTest extends KafkaClientPropagationBaseTest } } } - trace(1, 3) { + trace(1, 2) { span(0) { - name SHARED_TOPIC + " receive" - kind CONSUMER - hasNoParent() - attributes { - "$SemanticAttributes.MESSAGING_SYSTEM" "kafka" - "$SemanticAttributes.MESSAGING_DESTINATION" SHARED_TOPIC - "$SemanticAttributes.MESSAGING_DESTINATION_KIND" "topic" - "$SemanticAttributes.MESSAGING_OPERATION" "receive" - } - } - span(1) { name SHARED_TOPIC + " process" kind CONSUMER - childOf span(0) hasNoLinks() attributes { "$SemanticAttributes.MESSAGING_SYSTEM" "kafka" @@ -87,9 +75,9 @@ class KafkaClientPropagationDisabledTest extends KafkaClientPropagationBaseTest "kafka.offset" Long "kafka.record.queue_time_ms" { it >= 0 } } - span(2) { + span(1) { name "processing" - childOf span(1) + childOf span(0) } } } diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/InterceptorsTest.groovy b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/InterceptorsTest.groovy index 2d9544e59e15..655f59591bce 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/InterceptorsTest.groovy +++ b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/InterceptorsTest.groovy @@ -80,7 +80,6 @@ class InterceptorsTest extends KafkaClientBaseTest implements LibraryTestTrait { name SHARED_TOPIC + " receive" kind CONSUMER childOf span(1) - hasLink(span(1)) attributes { "$SemanticAttributes.MESSAGING_SYSTEM" "kafka" "$SemanticAttributes.MESSAGING_DESTINATION" SHARED_TOPIC diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/WrappersTest.groovy b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/WrappersTest.groovy index c93864535acc..ed45726dcee4 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/WrappersTest.groovy +++ b/instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/groovy/io/opentelemetry/instrumentation/kafkaclients/WrappersTest.groovy @@ -68,7 +68,6 @@ class WrappersTest extends KafkaClientBaseTest implements LibraryTestTrait { name SHARED_TOPIC + " receive" kind CONSUMER childOf span(1) - hasLink(span(1)) attributes { "$SemanticAttributes.MESSAGING_SYSTEM" "kafka" "$SemanticAttributes.MESSAGING_DESTINATION" SHARED_TOPIC diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java index d3cf508b7d80..8d0b3f4dc197 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java @@ -67,7 +67,7 @@ public static Instrumenter createConsumerReceiveInstrumen .addAttributesExtractor(attributesExtractor) .addAttributesExtractors(extractors) .setTimeExtractor(new KafkaConsumerTimeExtractor()) - .setDisabled(ExperimentalConfig.get().suppressMessagingReceiveSpans()) + .setDisabled(!ExperimentalConfig.get().messagingReceiveInstrumentationEnabled()) .newInstrumenter(SpanKindExtractor.alwaysConsumer()); } @@ -102,13 +102,13 @@ public static Instrumenter createConsumerReceiveInstrumen if (!KafkaPropagation.isPropagationEnabled()) { return builder.newInstrumenter(SpanKindExtractor.alwaysConsumer()); - } else if (ExperimentalConfig.get().suppressMessagingReceiveSpans()) { - return builder.newConsumerInstrumenter(KafkaConsumerRecordGetter.INSTANCE); - } else { + } else if (ExperimentalConfig.get().messagingReceiveInstrumentationEnabled()) { builder.addSpanLinksExtractor( SpanLinksExtractor.fromUpstreamRequest( GlobalOpenTelemetry.getPropagators(), KafkaConsumerRecordGetter.INSTANCE)); return builder.newInstrumenter(SpanKindExtractor.alwaysConsumer()); + } else { + return builder.newConsumerInstrumenter(KafkaConsumerRecordGetter.INSTANCE); } } diff --git a/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts b/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts index 506e630388e4..76080b0f132f 100644 --- a/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts +++ b/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts @@ -37,7 +37,6 @@ tasks { isFailOnNoMatchingTests = false } include("**/KafkaStreamsSuppressReceiveSpansTest.*") - jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true") } test { @@ -46,5 +45,6 @@ tasks { excludeTestsMatching("KafkaStreamsSuppressReceiveSpansTest") isFailOnNoMatchingTests = false } + jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true") } } diff --git a/instrumentation/spring/spring-kafka-2.7/javaagent/build.gradle.kts b/instrumentation/spring/spring-kafka-2.7/javaagent/build.gradle.kts index e9448cfeba38..55f0152f878b 100644 --- a/instrumentation/spring/spring-kafka-2.7/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-kafka-2.7/javaagent/build.gradle.kts @@ -34,5 +34,6 @@ tasks { // TODO run tests both with and without experimental span attributes jvmArgs("-Dotel.instrumentation.kafka.experimental-span-attributes=true") + jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true") } }