karafka / rdkafka-ruby

Modern and performant Kafka client library for Ruby based on librdkafka
https://karafka.io
Other
354 stars 120 forks source link

Feature request: extend Rdkafka::Error with instance name #181

Open mensfeld opened 2 years ago

mensfeld commented 2 years ago

(I am willing to implement it)

It would be good to have instance name (rd_kafka_name) in the error for debug purposes. Now we get an error message but there is no way to tie it back to particular native kafka instance. A change that would include the rd_kafka_name in the error would fix that.

basically something like this:

  mod.attach_function :rd_kafka_name, [:pointer], :string

FFI::Function.new(
  :void, [:pointer, :int, :string, :pointer]
) do |client_prr, err_code, reason, _opaque|
  if ::Rdkafka::Config.error_callback
    name = rd_kafka_name client_prr
    error = ::Rdkafka::RdkafkaError.new(name, err_code, broker_message: reason)
    ::Rdkafka::Config.error_callback.call(error)
    # or alternatively if not in error, we could pass it alongside but this would change the API, so not that nice
    ::Rdkafka::Config.error_callback.call(name, error)
  end
end

If :+1: then I can quickly add it.

thijsc commented 2 years ago

Sounds great

mensfeld commented 2 years ago

I will backport this once back from a short holiday. I have the code ready.