Skip to content

Commit 74430c0

Browse files
adinauerclaude
andcommitted
ref(samples): Clarify Kafka consumer tracing sample
Print the consumed Kafka record inside the manual consumer tracing callback so the sample shows where application processing happens. Update the console system test to assert the manual queue.process transaction and its manual consumer origin. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c52b8ad commit 74430c0

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/kafka/KafkaShowcase.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ private static Thread startConsumerWithSentryTracing(
112112
final ConsumerRecords<String, String> records =
113113
consumer.poll(Duration.ofMillis(500));
114114
for (final ConsumerRecord<String, String> record : records) {
115-
SentryKafkaConsumerTracing.withTracing(record, consumedLatch::countDown);
115+
SentryKafkaConsumerTracing.withTracing(
116+
record,
117+
() -> {
118+
System.out.println(
119+
"Consumed Kafka message from "
120+
+ record.topic()
121+
+ ": "
122+
+ record.value());
123+
consumedLatch.countDown();
124+
});
116125
if (consumedLatch.getCount() == 0) {
117126
break;
118127
}

sentry-samples/sentry-samples-console/src/test/kotlin/io/sentry/systemtest/ConsoleApplicationSystemTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class ConsoleApplicationSystemTest {
4242
}
4343

4444
testHelper.ensureTransactionReceived { transaction, _ ->
45-
testHelper.doesTransactionHaveOp(transaction, "queue.receive") &&
45+
testHelper.doesTransactionHaveOp(transaction, "queue.process") &&
46+
transaction.contexts.trace?.origin == "manual.queue.kafka.consumer" &&
4647
transaction.contexts.trace?.data?.get("messaging.system") == "kafka"
4748
}
4849
}

0 commit comments

Comments
 (0)