Class DebeziumTracingProducerInterceptor<K,V>

java.lang.Object
io.debezium.tracing.DebeziumTracingProducerInterceptor<K,V>
All Implemented Interfaces:
AutoCloseable, org.apache.kafka.clients.producer.ProducerInterceptor<K,V>, org.apache.kafka.common.Configurable

public class DebeziumTracingProducerInterceptor<K,V> extends Object implements org.apache.kafka.clients.producer.ProducerInterceptor<K,V>
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • openTelemetry

      private static final io.opentelemetry.api.OpenTelemetry openTelemetry
    • tracer

      private static final io.opentelemetry.api.trace.Tracer tracer
    • TEXT_MAP_PROPAGATOR

      private static final io.opentelemetry.context.propagation.TextMapPropagator TEXT_MAP_PROPAGATOR
    • GETTER

      private static final io.opentelemetry.context.propagation.TextMapGetter<org.apache.kafka.clients.producer.ProducerRecord<?,?>> GETTER
    • interceptorInstance

      private Object interceptorInstance
    • onSendMethod

      private Method onSendMethod
  • Constructor Details

    • DebeziumTracingProducerInterceptor

      public DebeziumTracingProducerInterceptor()
      The constructor for the DebeziumTracingProducerInterceptor.

      In this interceptor, we use a dynamic approach to handle the OpenTelemetry tracing interceptor due to versioning issues. The problem arises because different versions of OpenTelemetry have their tracing interceptor in different packages. For example, in versions before 1.23.0, the tracing interceptor is in the "io.opentelemetry.instrumentation.kafkaclients" package, but from version 1.23.0 onwards, it is in the "io.opentelemetry.instrumentation.kafkaclients.v2_6" package.

      The OpenTelemetry interceptor is also part of an alpha package, which means it's subject to change, and there is no guarantee of backward compatibility. That's why a dynamic approach is used here. We maintain an array of possible class names (OpenTelemetryInterceptorVersion) for the OpenTelemetry tracing interceptor, and we attempt to instantiate one of them at runtime. We also use reflection to access the 'onSend' method from the interceptor.

      This allows the Debezium Kafka Connector to work with different versions of OpenTelemetry.

  • Method Details

    • onSend

      public org.apache.kafka.clients.producer.ProducerRecord<K,V> onSend(org.apache.kafka.clients.producer.ProducerRecord<K,V> producerRecord)
      Specified by:
      onSend in interface org.apache.kafka.clients.producer.ProducerInterceptor<K,V>
    • onAcknowledgement

      public void onAcknowledgement(org.apache.kafka.clients.producer.RecordMetadata recordMetadata, Exception e)
      Specified by:
      onAcknowledgement in interface org.apache.kafka.clients.producer.ProducerInterceptor<K,V>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface org.apache.kafka.clients.producer.ProducerInterceptor<K,V>
    • configure

      public void configure(Map<String,?> map)
      Specified by:
      configure in interface org.apache.kafka.common.Configurable