Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ tasks {
withType<Test>().configureEach {
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
systemProperty("collectMetadata", findProperty("collectMetadata"))
jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true")
}

val testExperimental by registering(Test::class) {
Expand All @@ -99,11 +98,19 @@ tasks {
systemProperty("hasConsumerGroup", testLatestDeps)
}

val testReceiveSpansDisabled by registering(Test::class) {
testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath

systemProperty("hasConsumerGroup", testLatestDeps)
}

test {
systemProperty("hasConsumerGroup", testLatestDeps)
jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true")
}

check {
dependsOn(testing.suites, testExperimental)
dependsOn(testing.suites, testExperimental, testReceiveSpansDisabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public abstract class AbstractReactorKafkaTest {

private static final Logger logger = LoggerFactory.getLogger(AbstractReactorKafkaTest.class);

private static final boolean receiveTelemetryEnabled =
Boolean.getBoolean("otel.instrumentation.messaging.experimental.receive-telemetry.enabled");

@RegisterExtension
protected static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

Expand Down Expand Up @@ -153,6 +156,14 @@ protected void testSingleRecordProcess(
Flux<?> producer = sender.send(Flux.just(record));
testing.runWithSpan("producer", () -> producer.blockLast(Duration.ofSeconds(30)));

if (receiveTelemetryEnabled) {
assertWithReceiveTelemetry(record);
} else {
assertWithoutReceiveTelemetry(record);
}
}

private static void assertWithReceiveTelemetry(SenderRecord<String, String, Object> record) {
AtomicReference<SpanData> producerSpan = new AtomicReference<>();

testing.waitAndAssertSortedTraces(
Expand Down Expand Up @@ -184,6 +195,24 @@ protected void testSingleRecordProcess(
span -> span.hasName("consumer").hasParent(trace.getSpan(1))));
}

private static void assertWithoutReceiveTelemetry(SenderRecord<String, String, Object> record) {
testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("producer"),
span ->
span.hasName("testTopic publish")
.hasKind(SpanKind.PRODUCER)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(sendAttributes(record)),
span ->
span.hasName("testTopic process")
.hasKind(SpanKind.CONSUMER)
.hasParent(trace.getSpan(1))
.hasAttributesSatisfyingExactly(processAttributes(record)),
span -> span.hasName("consumer").hasParent(trace.getSpan(2))));
}

@SuppressWarnings("deprecation") // using deprecated semconv
protected static List<AttributeAssertion> sendAttributes(ProducerRecord<String, String> record) {
List<AttributeAssertion> assertions =
Expand Down
Loading