Skip to content

Commit 6157a5f

Browse files
committed
Add spacetime_worker_sender_errors_total metric
Currently we have a metric for reducer panics called `spacetime_worker_wasm_instance_errors_total`. This commit adds a metric for tracking errors returned from the module, like for example an Err result in Rust, or throwing a SenderError in TypeScript
1 parent 08011a7 commit 6157a5f

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

crates/core/src/host/wasm_common/module_host_actor.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use spacetimedb_datastore::locking_tx_datastore::FuncCallType;
44
use spacetimedb_datastore::locking_tx_datastore::ViewCall;
55
use spacetimedb_lib::db::raw_def::v9::Lifecycle;
66
use spacetimedb_lib::de::DeserializeSeed as _;
7+
use spacetimedb_lib::Hash;
78
use spacetimedb_primitives::ProcedureId;
89
use spacetimedb_primitives::ViewDatabaseId;
910
use spacetimedb_primitives::ViewId;
@@ -601,7 +602,13 @@ impl InstanceCommon {
601602
)
602603
}
603604
Err(ExecutionError::User(err)) => {
604-
log_reducer_error(inst.replica_ctx(), timestamp, reducer_name, &err);
605+
log_reducer_error(
606+
inst.replica_ctx(),
607+
timestamp,
608+
reducer_name,
609+
&err,
610+
&self.info.module_hash,
611+
);
605612
EventStatus::Failed(err.into())
606613
}
607614
// We haven't actually committed yet - `commit_and_broadcast_event` will commit
@@ -619,7 +626,13 @@ impl InstanceCommon {
619626
Ok(()) => EventStatus::Committed(DatabaseUpdate::default()),
620627
Err(err) => {
621628
let err = err.to_string();
622-
log_reducer_error(inst.replica_ctx(), timestamp, reducer_name, &err);
629+
log_reducer_error(
630+
inst.replica_ctx(),
631+
timestamp,
632+
reducer_name,
633+
&err,
634+
&self.info.module_hash,
635+
);
623636
EventStatus::Failed(err)
624637
}
625638
}
@@ -902,9 +915,20 @@ fn maybe_log_long_running_function(reducer_name: &str, total_duration: Duration)
902915
}
903916

904917
/// Logs an error `message` for `reducer` at `timestamp` into `replica_ctx`.
905-
fn log_reducer_error(replica_ctx: &ReplicaContext, timestamp: Timestamp, reducer: &str, message: &str) {
918+
fn log_reducer_error(
919+
replica_ctx: &ReplicaContext,
920+
timestamp: Timestamp,
921+
reducer: &str,
922+
message: &str,
923+
module_hash: &Hash,
924+
) {
906925
use database_logger::Record;
907926

927+
WORKER_METRICS
928+
.sender_errors
929+
.with_label_values(&replica_ctx.database_identity, module_hash, reducer)
930+
.inc();
931+
908932
log::info!("reducer returned error: {message}");
909933

910934
let record = Record {

crates/core/src/worker_metrics/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ metrics_group!(
246246
#[labels(caller_identity: Identity, module_hash: Hash, caller_connection_id: ConnectionId, reducer_symbol: str)]
247247
pub wasm_instance_errors: IntCounterVec,
248248

249+
#[name = spacetime_worker_sender_errors_total]
250+
#[help = "The number of sender errors returned from reducers."]
251+
#[labels(database_identity: Identity, module_hash: Hash, reducer_symbol: str)]
252+
pub sender_errors: IntCounterVec,
253+
249254
#[name = spacetime_worker_wasm_memory_bytes]
250255
#[help = "The number of bytes of linear memory allocated by the database's WASM module instance"]
251256
#[labels(database_identity: Identity)]

0 commit comments

Comments
 (0)