From 62d9cbacdb4cb3750355935481a3966fb424a5e3 Mon Sep 17 00:00:00 2001 From: Brandon Simmons Date: Sat, 5 Oct 2024 11:29:17 -0400 Subject: [PATCH] ENG-1071: add detailed traces for MBS validate/ and some benchmarks (#1209) ### What Set us up for more visibility into performance on prod. ### How Add traces V3_GIT_ORIGIN_REV_ID: 0ea011c1233a08bf4f9d55a9084809a6ffcd934d --- v3/Cargo.lock | 1 + v3/crates/lang-graphql/Cargo.toml | 1 + .../src/generate_graphql_schema.rs | 60 ++++++++++++------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/v3/Cargo.lock b/v3/Cargo.lock index 72c2b44d6b5ef..4bb754ff7fae0 100644 --- a/v3/Cargo.lock +++ b/v3/Cargo.lock @@ -3003,6 +3003,7 @@ dependencies = [ "serde_with", "smol_str", "thiserror", + "tracing-util", ] [[package]] diff --git a/v3/crates/lang-graphql/Cargo.toml b/v3/crates/lang-graphql/Cargo.toml index 903fdcc1f1eba..1e1eb761a2f43 100644 --- a/v3/crates/lang-graphql/Cargo.toml +++ b/v3/crates/lang-graphql/Cargo.toml @@ -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 } diff --git a/v3/crates/lang-graphql/src/generate_graphql_schema.rs b/v3/crates/lang-graphql/src/generate_graphql_schema.rs index 715827eaf1954..604f4bbf966ca 100644 --- a/v3/crates/lang-graphql/src/generate_graphql_schema.rs +++ b/v3/crates/lang-graphql/src/generate_graphql_schema.rs @@ -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 { @@ -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< @@ -29,29 +36,40 @@ pub fn build_namespace_schema< namespaced_getter: &NSGet, schema: &crate::schema::Schema, ) -> Result { - 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 {