Skip to content

Commit b7d333e

Browse files
authored
chore: Include previous status to failed metric (#735)
* chore: Include previous status to failed metric * chore: Improvements
1 parent bebce65 commit b7d333e

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/metrics/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ lazy_static! {
138138
};
139139

140140
// Counter for failed transactions (Failed, Expired, Canceled statuses).
141+
// Labels: relayer_id, network_type, failure_reason, previous_status.
142+
// Note: `previous_status` label added to track the pipeline stage before the failure
143+
// (e.g. "pending", "sent", "submitted"), enabling pre- vs post-submission attribution.
141144
pub static ref TRANSACTIONS_FAILED: CounterVec = {
142145
let opts = Opts::new("transactions_failed_total", "Total number of failed transactions");
143-
let counter_vec = CounterVec::new(opts, &["relayer_id", "network_type", "failure_reason"]).unwrap();
146+
let counter_vec = CounterVec::new(opts, &["relayer_id", "network_type", "failure_reason", "previous_status"]).unwrap();
144147
REGISTRY.register(Box::new(counter_vec.clone())).unwrap();
145148
counter_vec
146149
};

src/repositories/transaction/transaction_redis.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ impl RedisTransactionRepository {
694694
let is_final = is_final_state(new_status);
695695

696696
if !was_final && is_final {
697+
let previous_status = format!("{old_status:?}").to_lowercase();
697698
let meta = updated_tx.metadata.as_ref();
698699
let had_insufficient_fee = meta.is_some_and(|m| m.insufficient_fee_retries > 0);
699700
let had_try_again_later = meta.is_some_and(|m| m.try_again_later_retries > 0);
@@ -772,17 +773,32 @@ impl RedisTransactionRepository {
772773
})
773774
.unwrap_or("failed");
774775
TRANSACTIONS_FAILED
775-
.with_label_values(&[relayer_id, &network_type, failure_reason])
776+
.with_label_values(&[
777+
relayer_id,
778+
&network_type,
779+
failure_reason,
780+
&previous_status,
781+
])
776782
.inc();
777783
}
778784
TransactionStatus::Expired => {
779785
TRANSACTIONS_FAILED
780-
.with_label_values(&[relayer_id, &network_type, "expired"])
786+
.with_label_values(&[
787+
relayer_id,
788+
&network_type,
789+
"expired",
790+
&previous_status,
791+
])
781792
.inc();
782793
}
783794
TransactionStatus::Canceled => {
784795
TRANSACTIONS_FAILED
785-
.with_label_values(&[relayer_id, &network_type, "canceled"])
796+
.with_label_values(&[
797+
relayer_id,
798+
&network_type,
799+
"canceled",
800+
&previous_status,
801+
])
786802
.inc();
787803
}
788804
_ => {}

0 commit comments

Comments
 (0)