Add tracing support for GraphQL objects, interfaces and subscriptions#972
Add tracing support for GraphQL objects, interfaces and subscriptions#972ArsileLuci wants to merge 91 commits intographql-rust:masterfrom
Conversation
This reverts commit 753c80f.
tyranron
left a comment
There was a problem hiding this comment.
@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.
@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. | |||
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.
@ArsileLuci seems that shoud be:
__juniper_instrument_trace!(f, "execute_validated_query_async").await
juniper/src/util.rs
Outdated
| assert_eq!(&to_camel_case("")[..], ""); | ||
| } | ||
|
|
||
| #[cfg(feature = "tracing-futures")] |
There was a problem hiding this comment.
@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> |
juniper_codegen/src/util/mod.rs
Outdated
| } | ||
| } | ||
| }); | ||
| }) #trace_async; |
There was a problem hiding this comment.
and here it will be like
});
#trace_async
juniper_codegen/src/util/mod.rs
Outdated
| pub mod span_container; | ||
|
|
||
| #[cfg(feature = "tracing")] | ||
| pub mod tracing; |
There was a problem hiding this comment.
@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
| pub span: Span, | ||
|
|
||
| #[cfg(feature = "tracing")] | ||
| pub tracing: Option<tracing::Attr>, |
There was a problem hiding this comment.
@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.
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.
@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.
@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.
@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: