Refactored tracing extension to allow better span and event filtering and improve signal to noise
This commit is contained in:
parent
05b2473b52
commit
895dbfae7c
@ -1,7 +1,8 @@
|
|||||||
use crate::extensions::{Extension, ResolveInfo};
|
use crate::extensions::{Extension, ResolveInfo};
|
||||||
use crate::{QueryPathSegment, Variables};
|
use crate::{Variables};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use tracing::{span, Id, Level};
|
use tracing::{span, event, Id, Level};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// Tracing extension
|
/// Tracing extension
|
||||||
///
|
///
|
||||||
@ -15,12 +16,26 @@ pub struct Tracing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Extension for Tracing {
|
impl Extension for Tracing {
|
||||||
fn parse_start(&mut self, query_source: &str, _variables: &Variables) {
|
fn parse_start(&mut self, query_source: &str, variables: &Variables) {
|
||||||
let root_span = span!(target: "async-graphql", parent:None, Level::INFO, "query", source = query_source);
|
let root_span: tracing::Span = span!(
|
||||||
|
target: "async_graphql",
|
||||||
|
parent:None,
|
||||||
|
Level::INFO,
|
||||||
|
"graphql",
|
||||||
|
id = %Uuid::new_v4().to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(id) = root_span.id() {
|
if let Some(id) = root_span.id() {
|
||||||
tracing::dispatcher::get_default(|d| d.enter(&id));
|
tracing::dispatcher::get_default(|d| d.enter(&id));
|
||||||
self.root_id.replace(id);
|
self.root_id.replace(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event!(
|
||||||
|
target: "async_graphql::query",
|
||||||
|
Level::DEBUG,
|
||||||
|
%variables,
|
||||||
|
query = %query_source
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execution_end(&mut self) {
|
fn execution_end(&mut self) {
|
||||||
@ -34,27 +49,15 @@ impl Extension for Tracing {
|
|||||||
.resolve_id
|
.resolve_id
|
||||||
.parent
|
.parent
|
||||||
.and_then(|id| self.fields.get(&id))
|
.and_then(|id| self.fields.get(&id))
|
||||||
|
.or_else(|| self.root_id.as_ref())
|
||||||
.cloned();
|
.cloned();
|
||||||
let span = match &info.path_node.segment {
|
let span = span!(
|
||||||
QueryPathSegment::Index(idx) => span!(
|
target: "async_graphql::field",
|
||||||
target: "async-graphql",
|
parent: parent_span,
|
||||||
parent: parent_span,
|
Level::INFO,
|
||||||
Level::INFO,
|
"field",
|
||||||
"field",
|
path = %info.path_node,
|
||||||
index = *idx,
|
);
|
||||||
parent_type = info.parent_type,
|
|
||||||
return_type = info.return_type
|
|
||||||
),
|
|
||||||
QueryPathSegment::Name(name) => span!(
|
|
||||||
target: "async-graphql",
|
|
||||||
parent: parent_span,
|
|
||||||
Level::INFO,
|
|
||||||
"field",
|
|
||||||
name = name,
|
|
||||||
parent_type = info.parent_type,
|
|
||||||
return_type = info.return_type
|
|
||||||
),
|
|
||||||
};
|
|
||||||
if let Some(id) = span.id() {
|
if let Some(id) = span.id() {
|
||||||
tracing::dispatcher::get_default(|d| d.enter(&id));
|
tracing::dispatcher::get_default(|d| d.enter(&id));
|
||||||
self.fields.insert(info.resolve_id.current, id);
|
self.fields.insert(info.resolve_id.current, id);
|
||||||
|
Loading…
Reference in New Issue
Block a user