diff --git a/quaint/src/connector.rs b/quaint/src/connector.rs index c51f156e9445..de8bc64d22bb 100644 --- a/quaint/src/connector.rs +++ b/quaint/src/connector.rs @@ -10,7 +10,7 @@ //! querying interface. mod connection_info; -pub(crate) mod metrics; +pub mod metrics; mod queryable; mod result_set; #[cfg(any(feature = "mssql", feature = "postgresql", feature = "mysql"))] @@ -42,3 +42,5 @@ pub use transaction::*; #[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgresql"))] #[allow(unused_imports)] pub(crate) use type_identifier::*; + +pub use self::metrics::query; diff --git a/quaint/src/connector/metrics.rs b/quaint/src/connector/metrics.rs index d8fa04e65655..e806f98c1d8f 100644 --- a/quaint/src/connector/metrics.rs +++ b/quaint/src/connector/metrics.rs @@ -3,12 +3,7 @@ use tracing::{info_span, Instrument}; use crate::ast::{Params, Value}; use std::{future::Future, time::Instant}; -pub(crate) async fn query<'a, F, T, U>( - tag: &'static str, - query: &'a str, - params: &'a [Value<'_>], - f: F, -) -> crate::Result +pub async fn query<'a, F, T, U>(tag: &'static str, query: &'a str, params: &'a [Value<'_>], f: F) -> crate::Result where F: FnOnce() -> U + 'a, U: Future>, diff --git a/query-engine/js-connectors/src/queryable.rs b/query-engine/js-connectors/src/queryable.rs index f65e55d8d7ce..0a498b31e011 100644 --- a/query-engine/js-connectors/src/queryable.rs +++ b/query-engine/js-connectors/src/queryable.rs @@ -6,7 +6,10 @@ use async_trait::async_trait; use napi::{Env, JsObject}; use psl::datamodel_connector::Flavour; use quaint::{ - connector::{IsolationLevel, Transaction}, + connector::{ + metrics::{self}, + IsolationLevel, Transaction, + }, error::{Error, ErrorKind}, prelude::{Query as QuaintQuery, Queryable as QuaintQueryable, ResultSet, TransactionCapable}, visitor::{self, Visitor}, @@ -56,8 +59,10 @@ impl QuaintQueryable for JsBaseQueryable { } async fn query_raw(&self, sql: &str, params: &[Value<'_>]) -> quaint::Result { - let span = info_span!("js:query", user_facing = true); - self.do_query_raw(sql, params).instrument(span).await + metrics::query("js.query_raw", sql, params, move || async move { + self.do_query_raw(sql, params).await + }) + .await } async fn query_raw_typed(&self, sql: &str, params: &[Value<'_>]) -> quaint::Result { @@ -70,8 +75,10 @@ impl QuaintQueryable for JsBaseQueryable { } async fn execute_raw(&self, sql: &str, params: &[Value<'_>]) -> quaint::Result { - let span = info_span!("js:query", user_facing = true); - self.do_execute_raw(sql, params).instrument(span).await + metrics::query("js.execute_raw", sql, params, move || async move { + self.do_execute_raw(sql, params).await + }) + .await } async fn execute_raw_typed(&self, sql: &str, params: &[Value<'_>]) -> quaint::Result { @@ -79,8 +86,12 @@ impl QuaintQueryable for JsBaseQueryable { } async fn raw_cmd(&self, cmd: &str) -> quaint::Result<()> { - self.execute_raw(cmd, &[]).await?; - Ok(()) + let params = &[]; + metrics::query("js.raw_cmd", cmd, params, move || async move { + self.do_execute_raw(cmd, params).await?; + Ok(()) + }) + .await } async fn version(&self) -> quaint::Result> {