-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kafka): Report producer errors (#677)
- Loading branch information
Showing
5 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use rdkafka::producer::{DeliveryResult, ProducerContext}; | ||
use rdkafka::ClientContext; | ||
|
||
use relay_common::{metric, LogError}; | ||
|
||
use crate::metrics::RelayCounters; | ||
|
||
/// Kafka producer context that logs producer errors | ||
pub struct CaptureErrorContext; | ||
|
||
impl ClientContext for CaptureErrorContext {} | ||
|
||
impl ProducerContext for CaptureErrorContext { | ||
type DeliveryOpaque = (); | ||
|
||
/// This method is called after attempting to send a message to Kafka. | ||
/// It's called asynchronously for every message, so we want to handle errors explicitly here. | ||
fn delivery(&self, result: &DeliveryResult, _delivery_opaque: Self::DeliveryOpaque) { | ||
if let Err((error, _message)) = result { | ||
log::error!( | ||
"failed to produce message to Kafka (delivery callback): {}", | ||
LogError(error) | ||
); | ||
|
||
metric!(counter(RelayCounters::ProcessingProduceError) += 1); | ||
} | ||
} | ||
} | ||
|
||
pub type ThreadedProducer = rdkafka::producer::ThreadedProducer<CaptureErrorContext>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters