Skip to content

Commit

Permalink
ENG-1071: add detailed traces for MBS validate/ and some benchmarks (h…
Browse files Browse the repository at this point in the history
…asura#1209)

<!-- The PR description should answer 2 important questions: -->

### What

Set us up for more visibility into performance on prod.

### How

Add traces

V3_GIT_ORIGIN_REV_ID: 0ea011c1233a08bf4f9d55a9084809a6ffcd934d
  • Loading branch information
jberryman authored and hasura-bot committed Oct 5, 2024
1 parent 06ca697 commit 62d9cba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions v3/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions v3/crates/lang-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ serde_json = { workspace = true }
serde_with = { workspace = true }
smol_str = { workspace = true }
thiserror = { workspace = true }
tracing-util = { path = "../utils/tracing-util" }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
60 changes: 39 additions & 21 deletions v3/crates/lang-graphql/src/generate_graphql_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ for each namespace from the schema.
*/
use std::collections::HashMap;
use std::sync::OnceLock;
use tracing_util::SpanVisibility;
use tracing_util::{ErrorVisibility, TraceableError};

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand All @@ -20,6 +22,11 @@ pub enum Error {
#[error("unable to serialize to json: {0}")]
SerializeJson(#[from] serde_json::Error),
}
impl TraceableError for Error {
fn visibility(&self) -> ErrorVisibility {
ErrorVisibility::User
}
}

/// Generate GraphQL schema for a given namespace
pub fn build_namespace_schema<
Expand All @@ -29,29 +36,40 @@ pub fn build_namespace_schema<
namespaced_getter: &NSGet,
schema: &crate::schema::Schema<S>,
) -> Result<serde_json::Value, Error> {
let nr =
crate::validation::normalize_request(namespaced_getter, schema, introspection_request())
let tracer = tracing_util::global_tracer();
tracer.in_span(
"build_namespace_schema",
"Generate GraphQL schema for a given namespace",
SpanVisibility::Internal,
|| {
let nr = crate::validation::normalize_request(
namespaced_getter,
schema,
introspection_request(),
)
.map_err(|e| Error::NormalizeIntrospectionQuery(e.to_string()))?;
let mut result = HashMap::new();
for (_alias, field) in &nr.selection_set.fields {
let field_call = field.field_call().map_err(|_| Error::FieldCallNotFound)?;
match field_call.name.as_str() {
"__schema" => {
result.insert(
&field_call.name,
serde_json::to_value(crate::introspection::schema_type(
schema,
namespaced_getter,
&field.selection_set,
)?)?,
);
let mut result = HashMap::new();
for (_alias, field) in &nr.selection_set.fields {
let field_call = field.field_call().map_err(|_| Error::FieldCallNotFound)?;
match field_call.name.as_str() {
"__schema" => {
result.insert(
&field_call.name,
serde_json::to_value(crate::introspection::schema_type(
schema,
namespaced_getter,
&field.selection_set,
)?)?,
);
}
name => Err(Error::OnlySchemaFieldExpected {
name: name.to_string(),
})?,
}
}
name => Err(Error::OnlySchemaFieldExpected {
name: name.to_string(),
})?,
}
}
Ok(serde_json::to_value(result)?)
Ok(serde_json::to_value(result)?)
},
)
}

fn introspection_request() -> &'static crate::http::Request {
Expand Down

0 comments on commit 62d9cba

Please sign in to comment.