From 03450b5a76eaf7d6c6a020188d151a76c41e5b86 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Thu, 28 Mar 2024 14:19:10 -0700 Subject: [PATCH 1/2] capture error results from connector handlers in traces --- crates/mongodb-connector/src/mongo_connector.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/mongodb-connector/src/mongo_connector.rs b/crates/mongodb-connector/src/mongo_connector.rs index 77f16cc5..1d226050 100644 --- a/crates/mongodb-connector/src/mongo_connector.rs +++ b/crates/mongodb-connector/src/mongo_connector.rs @@ -18,6 +18,7 @@ use ndc_sdk::{ QueryResponse, SchemaResponse, }, }; +use tracing::instrument; use crate::{ api_type_conversions::{ @@ -36,6 +37,7 @@ impl Connector for MongoConnector { type Configuration = Configuration; type State = MongoConfig; + #[instrument(err, skip_all)] async fn parse_configuration( configuration_dir: impl AsRef + Send, ) -> Result { @@ -46,6 +48,10 @@ impl Connector for MongoConnector { } /// Reads database connection URI from environment variable + #[instrument(err, skip_all)] + // `instrument` automatically emits traces when this function returns. + // - `err` limits logging to `Err` results, at log level `error` + // - `skip_all` omits arguments from the trace async fn try_init_state( configuration: &Self::Configuration, _metrics: &mut prometheus::Registry, @@ -54,6 +60,7 @@ impl Connector for MongoConnector { Ok(state) } + #[instrument(err, skip_all)] fn fetch_metrics( _configuration: &Self::Configuration, _state: &Self::State, @@ -61,6 +68,7 @@ impl Connector for MongoConnector { Ok(()) } + #[instrument(err, skip_all)] async fn health_check( _configuration: &Self::Configuration, state: &Self::State, @@ -78,6 +86,7 @@ impl Connector for MongoConnector { mongo_capabilities_response().into() } + #[instrument(err, skip_all)] async fn get_schema( configuration: &Self::Configuration, ) -> Result, SchemaError> { @@ -85,6 +94,7 @@ impl Connector for MongoConnector { Ok(response.into()) } + #[instrument(err, skip_all)] async fn query_explain( _configuration: &Self::Configuration, state: &Self::State, @@ -103,6 +113,7 @@ impl Connector for MongoConnector { Ok(v2_to_v3_explain_response(response).into()) } + #[instrument(err, skip_all)] async fn mutation_explain( _configuration: &Self::Configuration, _state: &Self::State, @@ -113,6 +124,7 @@ impl Connector for MongoConnector { )) } + #[instrument(err, skip_all)] async fn mutation( _configuration: &Self::Configuration, state: &Self::State, @@ -121,6 +133,7 @@ impl Connector for MongoConnector { handle_mutation_request(state, request).await } + #[instrument(err, skip_all)] async fn query( _configuration: &Self::Configuration, state: &Self::State, From 6bca7be8c0928f5eab5f2b22adeb6d354ef36abc Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Thu, 28 Mar 2024 18:12:37 -0700 Subject: [PATCH 2/2] clippy has an issue with the instrument macro --- crates/mongodb-connector/src/mongo_connector.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/mongodb-connector/src/mongo_connector.rs b/crates/mongodb-connector/src/mongo_connector.rs index 1d226050..cc89c8e6 100644 --- a/crates/mongodb-connector/src/mongo_connector.rs +++ b/crates/mongodb-connector/src/mongo_connector.rs @@ -33,6 +33,7 @@ use crate::{capabilities::mongo_capabilities_response, mutation::handle_mutation pub struct MongoConnector; #[async_trait] +#[allow(clippy::blocks_in_conditions)] impl Connector for MongoConnector { type Configuration = Configuration; type State = MongoConfig;