-
Notifications
You must be signed in to change notification settings - Fork 426
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
Add tracing support for GraphQL objects, interfaces and subscriptions #972
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 753c80f.
cc @tyranron |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci thanks, quite raw and rough at the moment, needs more design polishing and some reconsiderations.
juniper/src/lib.rs
Outdated
.iter() | ||
.map(|e| format!("{}", e)) | ||
.collect::<Vec<_>>() | ||
.join("\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci here the allocation is redundant. There are easier and more obvious way to strip the last newline.
@@ -0,0 +1,130 @@ | |||
// Macros to instrument future spans. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci why not doc comment?
juniper/src/lib.rs
Outdated
&document, operation, root_node, variables, context, | ||
); | ||
|
||
__juniper_instrument_trace!(f, "execute_validated_query").await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci seems that shoud be:
__juniper_instrument_trace!(f, "execute_validated_query_async").await
juniper/src/util.rs
Outdated
@@ -51,3 +51,22 @@ fn test_to_camel_case() { | |||
assert_eq!(&to_camel_case("a")[..], "a"); | |||
assert_eq!(&to_camel_case("")[..], ""); | |||
} | |||
|
|||
#[cfg(feature = "tracing-futures")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci why "tracing-futures"
? It will complicate looking for feature-gated stuff. It's better to gate everything under the single "tracing"
feature, unless these two are going to be used separately, which is not our case.
juniper/src/util.rs
Outdated
|
||
/// Required to pass sanity tests when `Instrument` already imported. | ||
pub trait InstrumentInternal { | ||
fn __instrument(self, span: Span) -> Instrumented<Self> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci still, seems to be quite redundant.
juniper_codegen/src/util/mod.rs
Outdated
@@ -1291,7 +1366,7 @@ impl GraphQLTypeDefiniton { | |||
Err(e) => Err(ex.new_error(e)), | |||
} | |||
} | |||
}); | |||
}) #trace_async; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here it will be like
});
#trace_async
juniper_codegen/src/util/mod.rs
Outdated
@@ -4,6 +4,9 @@ pub mod duplicate; | |||
pub mod parse_impl; | |||
pub mod span_container; | |||
|
|||
#[cfg(feature = "tracing")] | |||
pub mod tracing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci it's better to move it from util
module to crate root and have a straight-forward tracing
module.
juniper_codegen/src/util/mod.rs
Outdated
@@ -680,6 +706,9 @@ pub struct GraphQLTypeDefinitionField { | |||
pub is_async: bool, | |||
pub default: Option<TokenStream>, | |||
pub span: Span, | |||
|
|||
#[cfg(feature = "tracing")] | |||
pub tracing: Option<tracing::Attr>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci also, as #[tracing]
represent a separate attribute, it woud be nice to not embed it here, but rather parse separately and use directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse separately and use directly.
You mean instead of expanding it within #[graphql_object]
/#[graphql_interface]
etc, we could just expand it separately for each field?
/// Derived GraphQL object marked with `trace = "complex"`. | ||
#[derive(GraphQLObject)] | ||
#[graphql(trace = "complex")] | ||
pub struct DerivedComplex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci I think we can use here #[tracing(complex)]
too.
Also, let's check whether we can do that for #[graphql_object]
macro, by looking up this attribute on a definition, parsing it and removing it. If not, it would be better to keep the similar to other cases format:
#[graphql_object(tracing(complex))]
This should also simplify the parsing, as we would have similar patterns everywhere.
juniper_codegen/src/util/tracing.rs
Outdated
name: Option<syn::LitStr>, | ||
|
||
/// Overwritten `level` of span generated, if `None` `Level::INFO` should be used. | ||
level: Option<syn::LitStr>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArsileLuci also, why parse all the attribute arguments by ourselves? Cannot we piggyback everything to upstream (tracing
crate)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyranron span!(...)
macro is pretty strict on argument order, and we need to cleanup arguments specific for juniper
, so a little of extra work here will allow to forget about argument order.
@ArsileLuci #971 is merged. |
@tyranron I want to discuss one feature in It could be implemented by dirty modification of Edit: This also can be solved if user implicitly reference Edit2: The solution is much simpler. User could just use |
Hi! Once this lands, I'd like to work on #953 and hope to be able to leverage this. My idea is to create a tracing collector and capture relevant span data to later be able to output the expected JSON. I'm wondering if there is enough already or if some tracing could be added (now or later):
Do you think something like that would be possible? |
What outstanding issues are we waiting on here? |
Hi @mathroc About this one:
Everything related to duration/time should be implemented on
The biggest disadvantage I see so far is making a whole lot of custom fields. In process of working on this PR I've tested this with stack |
thx @ArsileLuci for the feedback. Would you recommend doing something completely separate instead? |
If you need this exact feature, it could be implemented under feature flag either disabling or enabling it. The issue with Jaeger, could be simply solved, by just disabling this extra fields. Just explicitly mention it in the docs, and this should be enough.
I don't think there's any, except this branch being a bit old (and forgotten). |
@LegNeato this branch requires some serious review. We (me, @ArsileLuci and @ilslv) have plans to revive it after merging #975 After this PR we will land some subsequent ones, hopefully to fully close the question about tracing in |
Superseeds #720
Part of #953
This PR adds tracing support for GraphQL objects, interfaces and subscriptions.
#[tracing]
attribute that should be used#[graphql_object]
,#[graphql_interface]
attributes and derived GraphQL objects.#[instrument]
attribute on GraphQL fields, that can be used to tune how each field is tracedBefore review: