Skip to content

Commit c52b8ad

Browse files
adinauerclaude
andcommitted
ref(kafka): Remove raw consumer interceptor
Remove the raw Kafka consumer interceptor from sentry-kafka and update the console sample to use the manual consumer tracing helper instead. Keep producer tracing on the interceptor path and move consumer tracing to explicit record processing. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1f848a7 commit c52b8ad

5 files changed

Lines changed: 14 additions & 227 deletions

File tree

sentry-kafka/api/sentry-kafka.api

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ public final class io/sentry/kafka/BuildConfig {
33
public static final field VERSION_NAME Ljava/lang/String;
44
}
55

6-
public final class io/sentry/kafka/SentryKafkaConsumerInterceptor : org/apache/kafka/clients/consumer/ConsumerInterceptor {
7-
public static final field TRACE_ORIGIN Ljava/lang/String;
8-
public fun <init> ()V
9-
public fun <init> (Lio/sentry/IScopes;)V
10-
public fun close ()V
11-
public fun configure (Ljava/util/Map;)V
12-
public fun onCommit (Ljava/util/Map;)V
13-
public fun onConsume (Lorg/apache/kafka/clients/consumer/ConsumerRecords;)Lorg/apache/kafka/clients/consumer/ConsumerRecords;
14-
}
15-
166
public final class io/sentry/kafka/SentryKafkaConsumerTracing {
177
public static final field TRACE_ORIGIN Ljava/lang/String;
188
public static fun withTracing (Lorg/apache/kafka/clients/consumer/ConsumerRecord;Ljava/lang/Runnable;)V

sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaConsumerInterceptor.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaConsumerInterceptorTest.kt

Lines changed: 0 additions & 100 deletions
This file was deleted.

sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ public static void main(String[] args) throws InterruptedException {
184184
// cache.remove, and cache.flush spans as children of the active transaction.
185185
demonstrateCacheTracing();
186186

187-
// Kafka queue tracing with kafka-clients interceptors.
187+
// Kafka queue tracing with the kafka-clients producer interceptor and manual consumer tracing.
188188
//
189189
// Enable with: SENTRY_SAMPLE_KAFKA_BOOTSTRAP_SERVERS=localhost:9092
190190
if (kafkaEnabled) {
191-
KafkaShowcase.runKafkaWithSentryInterceptors(kafkaBootstrapServers);
191+
KafkaShowcase.runKafkaWithSentryTracing(kafkaBootstrapServers);
192192
}
193193

194194
// Performance feature

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.sentry.ISentryLifecycleToken;
44
import io.sentry.ITransaction;
55
import io.sentry.Sentry;
6-
import io.sentry.kafka.SentryKafkaConsumerInterceptor;
6+
import io.sentry.kafka.SentryKafkaConsumerTracing;
77
import io.sentry.kafka.SentryKafkaProducerInterceptor;
88
import java.time.Duration;
99
import java.util.Collections;
@@ -12,6 +12,7 @@
1212
import java.util.concurrent.CountDownLatch;
1313
import java.util.concurrent.TimeUnit;
1414
import org.apache.kafka.clients.consumer.ConsumerConfig;
15+
import org.apache.kafka.clients.consumer.ConsumerRecord;
1516
import org.apache.kafka.clients.consumer.ConsumerRecords;
1617
import org.apache.kafka.clients.consumer.KafkaConsumer;
1718
import org.apache.kafka.clients.producer.KafkaProducer;
@@ -26,10 +27,9 @@ public final class KafkaShowcase {
2627

2728
private KafkaShowcase() {}
2829

29-
public static void runKafkaWithSentryInterceptors(final String bootstrapServers) {
30+
public static void runKafkaWithSentryTracing(final String bootstrapServers) {
3031
final CountDownLatch consumedLatch = new CountDownLatch(1);
31-
final Thread consumerThread =
32-
startConsumerWithSentryInterceptor(bootstrapServers, consumedLatch);
32+
final Thread consumerThread = startConsumerWithSentryTracing(bootstrapServers, consumedLatch);
3333
final Properties producerProperties = createProducerPropertiesWithSentry(bootstrapServers);
3434

3535
final ITransaction transaction = Sentry.startTransaction("kafka-demo", "demo");
@@ -79,7 +79,7 @@ public static Properties createProducerPropertiesWithSentry(final String bootstr
7979
return producerProperties;
8080
}
8181

82-
public static Properties createConsumerPropertiesWithSentry(final String bootstrapServers) {
82+
public static Properties createConsumerProperties(final String bootstrapServers) {
8383
final Properties consumerProperties = new Properties();
8484
consumerProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
8585
consumerProperties.put(
@@ -90,24 +90,19 @@ public static Properties createConsumerPropertiesWithSentry(final String bootstr
9090
consumerProperties.put(
9191
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
9292

93-
// Required for Sentry queue tracing in kafka-clients consumer setup.
94-
consumerProperties.put(
95-
ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, SentryKafkaConsumerInterceptor.class.getName());
96-
9793
// Optional tuning for sample stability in CI/local runs.
9894
consumerProperties.put(ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, 2000);
9995
consumerProperties.put(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, 2000);
10096

10197
return consumerProperties;
10298
}
10399

104-
private static Thread startConsumerWithSentryInterceptor(
100+
private static Thread startConsumerWithSentryTracing(
105101
final String bootstrapServers, final CountDownLatch consumedLatch) {
106102
final Thread consumerThread =
107103
new Thread(
108104
() -> {
109-
final Properties consumerProperties =
110-
createConsumerPropertiesWithSentry(bootstrapServers);
105+
final Properties consumerProperties = createConsumerProperties(bootstrapServers);
111106

112107
try (KafkaConsumer<String, String> consumer =
113108
new KafkaConsumer<>(consumerProperties)) {
@@ -116,9 +111,11 @@ private static Thread startConsumerWithSentryInterceptor(
116111
while (!Thread.currentThread().isInterrupted() && consumedLatch.getCount() > 0) {
117112
final ConsumerRecords<String, String> records =
118113
consumer.poll(Duration.ofMillis(500));
119-
if (!records.isEmpty()) {
120-
consumedLatch.countDown();
121-
break;
114+
for (final ConsumerRecord<String, String> record : records) {
115+
SentryKafkaConsumerTracing.withTracing(record, consumedLatch::countDown);
116+
if (consumedLatch.getCount() == 0) {
117+
break;
118+
}
122119
}
123120
}
124121
} catch (Exception ignored) {

0 commit comments

Comments
 (0)