Skip to content

Commit 32445f8

Browse files
goffrieConvex, Inc.
authored and
Convex, Inc.
committed
Log if a (non root) component calls getUserIdentity (#36030)
GitOrigin-RevId: 52c7eb4326b4e325a9fca3cb0ba008a10358babd
1 parent 132fb75 commit 32445f8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crates/isolate/src/environment/udf/async_syscall.rs

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ use crate::{
113113
isolate2::client::QueryId,
114114
metrics::{
115115
async_syscall_timer,
116+
log_component_get_user_identity,
116117
log_run_udf,
117118
},
118119
};
@@ -773,6 +774,9 @@ impl<RT: Runtime, P: AsyncSyscallProvider<RT>> DatabaseSyscallsV1<RT, P> {
773774
// TODO: Somehow make the Transaction aware of the dependency on the user.
774775
let tx = provider.tx()?;
775776
let user_identity = tx.user_identity();
777+
if !provider.component()?.is_root() {
778+
log_component_get_user_identity(user_identity.is_some());
779+
}
776780
if let Some(user_identity) = user_identity {
777781
return user_identity.try_into();
778782
}

crates/isolate/src/metrics.rs

+17
Original file line numberDiff line numberDiff line change
@@ -696,3 +696,20 @@ pub fn log_run_udf(
696696
],
697697
);
698698
}
699+
700+
register_convex_counter!(
701+
COMPONENT_GET_USER_IDENTITY_TOTAL,
702+
"Number of times that components call getUserIdentity()",
703+
&["has_user_identity"]
704+
);
705+
706+
pub fn log_component_get_user_identity(has_user_identity: bool) {
707+
log_counter_with_labels(
708+
&COMPONENT_GET_USER_IDENTITY_TOTAL,
709+
1,
710+
vec![StaticMetricLabel::new(
711+
"has_user_identity",
712+
has_user_identity.as_label(),
713+
)],
714+
);
715+
}

0 commit comments

Comments
 (0)