Skip to content

Commit 0ca42c8

Browse files
adinauerclaude
andcommitted
ref(kafka): Reimplement SentryKafkaProducer as a dynamic Proxy
Replace the concrete `implements Producer<K,V>` class with a `Proxy.newProxyInstance`-based wrapper that intercepts only the two `send()` overloads and forwards every other method reflectively to the delegate. The concrete class required explicitly delegating every method on the `Producer` interface, coupling the wrapper to a specific Kafka version: `clientInstanceId(Duration)` was added in Kafka 3.7, and the deprecated `sendOffsetsToTransaction(Map, String)` was removed in Kafka 4.0. The dynamic proxy has no such coupling — new or removed interface methods are handled automatically, giving full compatibility across all Kafka client versions. Public API change: `SentryKafkaProducer` is now a utility class with static `wrap()` overloads instead of constructors. Callers wrap a producer with `SentryKafkaProducer.wrap(producer)`. The Spring BPP and console sample are updated accordingly. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1e293c6 commit 0ca42c8

6 files changed

Lines changed: 219 additions & 267 deletions

File tree

sentry-kafka/api/sentry-kafka.api

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,11 @@ public final class io/sentry/kafka/SentryKafkaConsumerTracing {
99
public static fun withTracing (Lorg/apache/kafka/clients/consumer/ConsumerRecord;Ljava/util/concurrent/Callable;)Ljava/lang/Object;
1010
}
1111

12-
public final class io/sentry/kafka/SentryKafkaProducer : org/apache/kafka/clients/producer/Producer {
12+
public final class io/sentry/kafka/SentryKafkaProducer {
1313
public static final field SENTRY_ENQUEUED_TIME_HEADER Ljava/lang/String;
1414
public static final field TRACE_ORIGIN Ljava/lang/String;
15-
public fun <init> (Lorg/apache/kafka/clients/producer/Producer;)V
16-
public fun <init> (Lorg/apache/kafka/clients/producer/Producer;Lio/sentry/IScopes;)V
17-
public fun <init> (Lorg/apache/kafka/clients/producer/Producer;Lio/sentry/IScopes;Ljava/lang/String;)V
18-
public fun abortTransaction ()V
19-
public fun beginTransaction ()V
20-
public fun clientInstanceId (Ljava/time/Duration;)Lorg/apache/kafka/common/Uuid;
21-
public fun close ()V
22-
public fun close (Ljava/time/Duration;)V
23-
public fun commitTransaction ()V
24-
public fun flush ()V
25-
public fun getDelegate ()Lorg/apache/kafka/clients/producer/Producer;
26-
public fun initTransactions ()V
27-
public fun metrics ()Ljava/util/Map;
28-
public fun partitionsFor (Ljava/lang/String;)Ljava/util/List;
29-
public fun send (Lorg/apache/kafka/clients/producer/ProducerRecord;)Ljava/util/concurrent/Future;
30-
public fun send (Lorg/apache/kafka/clients/producer/ProducerRecord;Lorg/apache/kafka/clients/producer/Callback;)Ljava/util/concurrent/Future;
31-
public fun sendOffsetsToTransaction (Ljava/util/Map;Ljava/lang/String;)V
32-
public fun sendOffsetsToTransaction (Ljava/util/Map;Lorg/apache/kafka/clients/consumer/ConsumerGroupMetadata;)V
33-
public fun toString ()Ljava/lang/String;
15+
public static fun wrap (Lorg/apache/kafka/clients/producer/Producer;)Lorg/apache/kafka/clients/producer/Producer;
16+
public static fun wrap (Lorg/apache/kafka/clients/producer/Producer;Lio/sentry/IScopes;)Lorg/apache/kafka/clients/producer/Producer;
17+
public static fun wrap (Lorg/apache/kafka/clients/producer/Producer;Lio/sentry/IScopes;Ljava/lang/String;)Lorg/apache/kafka/clients/producer/Producer;
3418
}
3519

0 commit comments

Comments
 (0)