lib/waterdrop/instrumentation/callbacks/delivery.rb in waterdrop-2.7.0.rc2 vs lib/waterdrop/instrumentation/callbacks/delivery.rb in waterdrop-2.7.0

- old
+ new

@@ -42,9 +42,20 @@ elsif @transactional && PURGE_ERRORS.include?(error_code) instrument_purged(delivery_report) else instrument_error(delivery_report) end + # This runs from the rdkafka thread, thus we want to safe-guard it and prevent absolute + # crashes even if the instrumentation code fails. If it would bubble-up, it could crash + # the rdkafka background thread + rescue StandardError => e + @monitor.instrument( + 'error.occurred', + caller: self, + error: e, + producer_id: @producer_id, + type: 'callbacks.delivery.error' + ) end private # @param delivery_report [Rdkafka::Producer::DeliveryReport] delivery report