-
Couldn't load subscription status.
- Fork 441
Add tracing support for GraphQL objects, interfaces and subscriptions #972
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
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
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.
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
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
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
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
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
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
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?
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
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 tracing that is currently risky to implement in Juniper. This is so called Empty fields, due to how we resolve fields we cannot use it in actual resolver (fn that's called within resolve_field and resolve_field_async to get value), we're limited to context of resolve_field or resolve_field_async.
It could be implemented by dirty modification of fns signature, but it's a little bit unfair, I guess.
Edit:
This also can be solved if user implicitly reference Span passed to fn, similarly to how Context and Executor passed, this variant more fair and clean than one suggested above.
Edit2:
The solution is much simpler. User could just use tracing::Span::current() to get access to current Span within resolver fn. So we don't need to bother about dealing with it.
mathroc
commented
Nov 24, 2021
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):
"tracing": {
"version": 1,
"startTime": <>, → that would be the "enter execute"
"endTime": <>, → "close execute"
"duration": <>, → the duration of the "execute" span
"parsing": { → I don't think this is present at the moment
"startOffset": <>,
"duration": <>,
},
"validation": { -> there's "validate_document" & "validate_input_values" but I don't know if a duration can be extracted from simple spans. Should they be wrapped by a "start/close validation" span ?
"startOffset": <>,
"duration": <>,
},
"execution": {
"resolvers": [ → They are traced. I would need to check if, 1: they can be identified easily, 2: everything below can be extracted from the span or could be added later
{
"path": [<>, ...],
"parentType": <>,
"fieldName": <>,
"returnType": <>,
"startOffset": <>,
"duration": <>,
},
...
]
}
Do you think something like that would be possible?
What outstanding issues are we waiting on here?
Hi @mathroc
About this one:
"validation": { -> there's "validate_document" & "validate_input_values" but I don't know if a duration can be extracted from simple spans. Should they be wrapped by a "start/close validation"
Everything related to duration/time should be implemented on Subscriber side.
1: they can be identified easily, 2: everything below can be extracted from the span or could be added later
-
It's not so simple, probably the only way to identify whether this is field resolver or not is to add custom marker field in every resolver, something like
juniper-resolver=true. -
Let's walk through every field and check what we can do:
- path: This will involve some work but all resolver spans follow one naming schema
<TypeName>.<resolverName>. Combining it with custom marker field, mentioned above, you can walkthrough every single span and build resolver chain. - parentType: If I understand it right this is
<TypeName>in span name so there should be no problems with it. - fieldName: Same to
parentTypebut this is<resolverName> - returnType: This should be implemented, probably using late binding fields
- startOffset and duration: also should be implemented manually
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 tracing -> tracing_opentelemetry -> opentelemetry_jaeger and all custom fields were sent to Jaeger. This resulted in Jaeger denying nearly half of my traces because "they are too large".
mathroc
commented
Nov 25, 2021
thx @ArsileLuci for the feedback. Would you recommend doing something completely separate instead?
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.
What outstanding issues are we waiting on here?
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 juniper.
4bb3114 to
33db991
Compare
37a5ec0 to
6036544
Compare
Uh oh!
There was an error while loading. Please reload this page.
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: