Support suppress-messaging-receive-span in JMS (#4204)
* Support suppress-messaging-receive-span in JMS * Spotless
This commit is contained in:
parent
c7a7b4515c
commit
48e42be821
|
@ -18,20 +18,45 @@ muzzle {
|
|||
|
||||
testSets {
|
||||
create("jms2Test")
|
||||
create("jms2TestReceiveSpansDisabled") {
|
||||
extendsFrom("jms2Test")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
val testReceiveSpansDisabled by registering(Test::class) {
|
||||
filter {
|
||||
includeTestsMatching("SpringListenerJms1SuppressReceiveSpansTest")
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
include("**/SpringListenerJms1SuppressReceiveSpansTest.*")
|
||||
jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true")
|
||||
}
|
||||
|
||||
val jms2Test by existing(Test::class) {
|
||||
filter {
|
||||
// this is needed because "test.dependsOn jms2Test", and so without this,
|
||||
// running a single test in the default test set will fail
|
||||
setFailOnNoMatchingTests(false)
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
}
|
||||
|
||||
named<Test>("test") {
|
||||
val jms2TestReceiveSpansDisabled by existing(Test::class) {
|
||||
filter {
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true")
|
||||
}
|
||||
|
||||
test {
|
||||
dependsOn(testReceiveSpansDisabled)
|
||||
dependsOn(jms2Test)
|
||||
dependsOn(jms2TestReceiveSpansDisabled)
|
||||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].getService())
|
||||
filter {
|
||||
excludeTestsMatching("SpringListenerJms1SuppressReceiveSpansTest")
|
||||
isFailOnNoMatchingTests = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,4 +79,7 @@ dependencies {
|
|||
// this doesn't exist in maven central, and doesn't seem to be needed anyways
|
||||
exclude("org.jboss.naming", "jnpserver")
|
||||
}
|
||||
|
||||
// this is just to avoid a bit more copy-pasting
|
||||
add("jms2TestReceiveSpansDisabledImplementation", sourceSets["jms2Test"].output)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import listener.Config
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
|
||||
import javax.jms.ConnectionFactory
|
||||
|
||||
class SpringListenerJms2SuppressReceiveSpansTest extends AgentInstrumentationSpecification {
|
||||
def "receiving message in spring listener generates spans"() {
|
||||
setup:
|
||||
def context = new AnnotationConfigApplicationContext(Config)
|
||||
def factory = context.getBean(ConnectionFactory)
|
||||
def template = new JmsTemplate(factory)
|
||||
|
||||
template.convertAndSend("SpringListenerJms2", "a message")
|
||||
|
||||
expect:
|
||||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
Jms2Test.producerSpan(it, 0, "queue", "SpringListenerJms2")
|
||||
Jms2Test.consumerSpan(it, 1, "queue", "SpringListenerJms2", "", span(0), "process")
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
context.close()
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.jms;
|
||||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.instrumentation.api.config.ExperimentalConfig;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
|
||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||
|
@ -46,6 +47,7 @@ public final class JmsSingletons {
|
|||
.addAttributesExtractor(attributesExtractor)
|
||||
.setTimeExtractors(
|
||||
MessageWithDestination::startTime, (request, response, error) -> request.endTime())
|
||||
.setDisabled(ExperimentalConfig.get().suppressMessagingReceiveSpans())
|
||||
.newInstrumenter(SpanKindExtractor.alwaysConsumer());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||
import listener.Config
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.jms.core.JmsTemplate
|
||||
|
||||
import javax.jms.ConnectionFactory
|
||||
|
||||
import static Jms1Test.consumerSpan
|
||||
import static Jms1Test.producerSpan
|
||||
|
||||
class SpringListenerJms1SuppressReceiveSpansTest extends AgentInstrumentationSpecification {
|
||||
|
||||
def "receiving message in spring listener generates spans"() {
|
||||
setup:
|
||||
def context = new AnnotationConfigApplicationContext(Config)
|
||||
def factory = context.getBean(ConnectionFactory)
|
||||
def template = new JmsTemplate(factory)
|
||||
|
||||
template.convertAndSend("SpringListenerJms1", "a message")
|
||||
|
||||
expect:
|
||||
assertTraces(1) {
|
||||
trace(0, 2) {
|
||||
producerSpan(it, 0, "queue", "SpringListenerJms1")
|
||||
consumerSpan(it, 1, "queue", "SpringListenerJms1", "", span(0), "process")
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
context.stop()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue