这是indexloc提供的服务,不要输入任何密码
Skip to content

capture error results from connector handlers in traces #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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