Skip to content

Commit

Permalink
capture error results from connector handlers in traces (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj authored Apr 4, 2024
1 parent 7d947d5 commit e755b1e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/mongodb-connector/src/mongo_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ndc_sdk::{
QueryResponse, SchemaResponse,
},
};
use tracing::instrument;

use crate::{
api_type_conversions::{
Expand All @@ -29,10 +30,12 @@ use crate::{capabilities::mongo_capabilities_response, mutation::handle_mutation
#[derive(Clone, Default)]
pub struct MongoConnector;

#[allow(clippy::blocks_in_conditions)]
#[async_trait]
impl ConnectorSetup for MongoConnector {
type Connector = MongoConnector;

#[instrument(err, skip_all)]
async fn parse_configuration(
&self,
configuration_dir: impl AsRef<Path> + Send,
Expand All @@ -44,6 +47,10 @@ impl ConnectorSetup 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(
&self,
configuration: &Configuration,
Expand All @@ -54,18 +61,21 @@ impl ConnectorSetup for MongoConnector {
}
}

#[allow(clippy::blocks_in_conditions)]
#[async_trait]
impl Connector for MongoConnector {
type Configuration = Configuration;
type State = MongoConfig;

#[instrument(err, skip_all)]
fn fetch_metrics(
_configuration: &Self::Configuration,
_state: &Self::State,
) -> Result<(), FetchMetricsError> {
Ok(())
}

#[instrument(err, skip_all)]
async fn health_check(
_configuration: &Self::Configuration,
state: &Self::State,
Expand All @@ -83,13 +93,15 @@ impl Connector for MongoConnector {
mongo_capabilities_response().into()
}

#[instrument(err, skip_all)]
async fn get_schema(
configuration: &Self::Configuration,
) -> Result<JsonResponse<SchemaResponse>, SchemaError> {
let response = crate::schema::get_schema(configuration).await?;
Ok(response.into())
}

#[instrument(err, skip_all)]
async fn query_explain(
configuration: &Self::Configuration,
state: &Self::State,
Expand All @@ -109,6 +121,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,
Expand All @@ -119,6 +132,7 @@ impl Connector for MongoConnector {
))
}

#[instrument(err, skip_all)]
async fn mutation(
_configuration: &Self::Configuration,
state: &Self::State,
Expand All @@ -127,6 +141,7 @@ impl Connector for MongoConnector {
handle_mutation_request(state, request).await
}

#[instrument(err, skip_all)]
async fn query(
configuration: &Self::Configuration,
state: &Self::State,
Expand Down

0 comments on commit e755b1e

Please sign in to comment.