Skip to content

Commit d5fb096

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 3ea5fde commit d5fb096

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::ViewCallInfo;
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::TableId;
910
use spacetimedb_primitives::ViewFnPtr;
@@ -694,7 +695,13 @@ impl InstanceCommon {
694695
)
695696
}
696697
Err(ExecutionError::User(err)) => {
697-
log_reducer_error(inst.replica_ctx(), timestamp, reducer_name, &err);
698+
log_reducer_error(
699+
inst.replica_ctx(),
700+
timestamp,
701+
reducer_name,
702+
&err,
703+
&self.info.module_hash,
704+
);
698705
EventStatus::Failed(err.into())
699706
}
700707
// We haven't actually committed yet - `commit_and_broadcast_event` will commit
@@ -712,7 +719,13 @@ impl InstanceCommon {
712719
Ok(()) => EventStatus::Committed(DatabaseUpdate::default()),
713720
Err(err) => {
714721
let err = err.to_string();
715-
log_reducer_error(inst.replica_ctx(), timestamp, reducer_name, &err);
722+
log_reducer_error(
723+
inst.replica_ctx(),
724+
timestamp,
725+
reducer_name,
726+
&err,
727+
&self.info.module_hash,
728+
);
716729
EventStatus::Failed(err)
717730
}
718731
}
@@ -1118,9 +1131,20 @@ fn maybe_log_long_running_function(reducer_name: &str, total_duration: Duration)
11181131
}
11191132

11201133
/// Logs an error `message` for `reducer` at `timestamp` into `replica_ctx`.
1121-
fn log_reducer_error(replica_ctx: &ReplicaContext, timestamp: Timestamp, reducer: &str, message: &str) {
1134+
fn log_reducer_error(
1135+
replica_ctx: &ReplicaContext,
1136+
timestamp: Timestamp,
1137+
reducer: &str,
1138+
message: &str,
1139+
module_hash: &Hash,
1140+
) {
11221141
use database_logger::Record;
11231142

1143+
WORKER_METRICS
1144+
.sender_errors
1145+
.with_label_values(&replica_ctx.database_identity, module_hash, reducer)
1146+
.inc();
1147+
11241148
log::info!("reducer returned error: {message}");
11251149

11261150
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)