diff --git a/candid/evm_rpc.did b/candid/evm_rpc.did index a5e9e309..4f38aeee 100644 --- a/candid/evm_rpc.did +++ b/candid/evm_rpc.did @@ -132,7 +132,7 @@ type Metrics = record { responses : vec record { record { text; text; text }; nat64 }; inconsistentResponses : vec record { record { text; text }; nat64 }; cyclesCharged : vec record { record { text; text }; nat }; - errHttpOutcall : vec record { record { text; text }; nat64 }; + errHttpOutcall : vec record { record { text; text; RejectionCode }; nat64 }; }; type MultiFeeHistoryResult = variant { Consistent : FeeHistoryResult; diff --git a/src/http.rs b/src/http.rs index abb4701e..c89eb7c0 100644 --- a/src/http.rs +++ b/src/http.rs @@ -94,7 +94,7 @@ pub async fn http_request( Ok(response) } Err((code, message)) => { - add_metric_entry!(err_http_outcall, (rpc_method, rpc_host), 1); + add_metric_entry!(err_http_outcall, (rpc_method, rpc_host, code), 1); Err(HttpOutcallError::IcError { code, message }.into()) } } diff --git a/src/types.rs b/src/types.rs index dca2292f..11833fe2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -3,6 +3,7 @@ use crate::memory::get_api_key; use crate::util::hostname_from_url; use crate::validate::validate_api_key; use candid::CandidType; +use ic_cdk::api::call::RejectionCode; use ic_cdk::api::management_canister::http_request::HttpHeader; use ic_stable_structures::storable::Bound; use ic_stable_structures::Storable; @@ -115,6 +116,22 @@ impl MetricLabels for MetricHttpStatusCode { } } +impl MetricLabels for RejectionCode { + fn metric_labels(&self) -> Vec<(&str, &str)> { + let code = match self { + RejectionCode::NoError => "NO_ERROR", + RejectionCode::SysFatal => "SYS_FATAL", + RejectionCode::SysTransient => "SYS_TRANSIENT", + RejectionCode::DestinationInvalid => "DESTINATION_INVALID", + RejectionCode::CanisterReject => "CANISTER_REJECT", + RejectionCode::CanisterError => "CANISTER_ERROR", + RejectionCode::Unknown => "UNKNOWN", + }; + + vec![("code", code)] + } +} + #[derive(Clone, Debug, Default, PartialEq, Eq, CandidType, Deserialize)] pub struct Metrics { pub requests: HashMap<(MetricRpcMethod, MetricRpcHost), u64>, @@ -124,7 +141,7 @@ pub struct Metrics { #[serde(rename = "cyclesCharged")] pub cycles_charged: HashMap<(MetricRpcMethod, MetricRpcHost), u128>, #[serde(rename = "errHttpOutcall")] - pub err_http_outcall: HashMap<(MetricRpcMethod, MetricRpcHost), u64>, + pub err_http_outcall: HashMap<(MetricRpcMethod, MetricRpcHost, RejectionCode), u64>, } #[derive(Clone, Copy, Debug, PartialEq, Eq)]