Skip to content

Commit

Permalink
Support suppress-messaging-receive-span in JMS (#4204)
Browse files Browse the repository at this point in the history
* Support suppress-messaging-receive-span in JMS

* Spotless
  • Loading branch information
trask authored Sep 28, 2021
1 parent c7a7b45 commit 48e42be
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
32 changes: 30 additions & 2 deletions instrumentation/jms-1.1/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

val jms2TestReceiveSpansDisabled by existing(Test::class) {
filter {
isFailOnNoMatchingTests = false
}
jvmArgs("-Dotel.instrumentation.common.experimental.suppress-messaging-receive-spans=true")
}

named<Test>("test") {
test {
dependsOn(testReceiveSpansDisabled)
dependsOn(jms2Test)
dependsOn(jms2TestReceiveSpansDisabled)
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].getService())
filter {
excludeTestsMatching("SpringListenerJms1SuppressReceiveSpansTest")
isFailOnNoMatchingTests = false
}
}
}

Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +47,7 @@ private static Instrumenter<MessageWithDestination, Void> buildConsumerInstrumen
.addAttributesExtractor(attributesExtractor)
.setTimeExtractors(
MessageWithDestination::startTime, (request, response, error) -> request.endTime())
.setDisabled(ExperimentalConfig.get().suppressMessagingReceiveSpans())
.newInstrumenter(SpanKindExtractor.alwaysConsumer());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 48e42be

Please sign in to comment.