Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ lazy_static! {
};

// Counter for failed transactions (Failed, Expired, Canceled statuses).
// Labels: relayer_id, network_type, failure_reason, previous_status.
// Note: `previous_status` label added to track the pipeline stage before the failure
// (e.g. "pending", "sent", "submitted"), enabling pre- vs post-submission attribution.
pub static ref TRANSACTIONS_FAILED: CounterVec = {
let opts = Opts::new("transactions_failed_total", "Total number of failed transactions");
let counter_vec = CounterVec::new(opts, &["relayer_id", "network_type", "failure_reason"]).unwrap();
let counter_vec = CounterVec::new(opts, &["relayer_id", "network_type", "failure_reason", "previous_status"]).unwrap();
REGISTRY.register(Box::new(counter_vec.clone())).unwrap();
counter_vec
};
Expand Down
22 changes: 19 additions & 3 deletions src/repositories/transaction/transaction_redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ impl RedisTransactionRepository {
let is_final = is_final_state(new_status);

if !was_final && is_final {
let previous_status = format!("{old_status:?}").to_lowercase();
let meta = updated_tx.metadata.as_ref();
let had_insufficient_fee = meta.is_some_and(|m| m.insufficient_fee_retries > 0);
let had_try_again_later = meta.is_some_and(|m| m.try_again_later_retries > 0);
Expand Down Expand Up @@ -772,17 +773,32 @@ impl RedisTransactionRepository {
})
.unwrap_or("failed");
TRANSACTIONS_FAILED
.with_label_values(&[relayer_id, &network_type, failure_reason])
.with_label_values(&[
relayer_id,
&network_type,
failure_reason,
&previous_status,
])
.inc();
}
TransactionStatus::Expired => {
TRANSACTIONS_FAILED
.with_label_values(&[relayer_id, &network_type, "expired"])
.with_label_values(&[
relayer_id,
&network_type,
"expired",
&previous_status,
])
.inc();
}
TransactionStatus::Canceled => {
TRANSACTIONS_FAILED
.with_label_values(&[relayer_id, &network_type, "canceled"])
.with_label_values(&[
relayer_id,
&network_type,
"canceled",
&previous_status,
])
.inc();
}
_ => {}
Expand Down
Loading