-
Notifications
You must be signed in to change notification settings - Fork 397
fix(graphql): handle nil value for locations in unified_trace #5025
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
base: master
Are you sure you want to change the base?
fix(graphql): handle nil value for locations in unified_trace #5025
Conversation
f3a2709 to
04a7bc3
Compare
|
Hey @codella, thanks for spotting this and sending a fix our way! If you happen to have the stack trace of one of those |
Hey! Thanks for being so snappy! 😲 I updated the description with the stack trace 🚀 |
|
@ivoanjo maybe you can help me. I am running the GraphQL tests with |
04a7bc3 to
dad0df2
Compare
|
Ah, I think you want I believe we have them separate because this functionality depends on modern graphql gem versions, yet we still want to support (and test with) the old ones. |
|
@ivoanjo I've been spending some time trying to add a test in Do you have any pointers, or alternative ways to write a test for it? I'm a bit puzzled that I couldn't get a test to replicate the issue, given that |
|
Good question... I spent a few minutes looking into the graphql gem and our tests and how we may trigger the issue to then test the fix, and I also couldn't trigger the error. TBH I think the fact that this is proving hard to test via that route is suggesting to me that it's not the right way to go, given what we want to test here. Specifically, we want to test that some specific query in some situation doesn't break. But if this case is possible (you've definitely seen it in production) but awkward to trigger (we've both not had success at this), I'm thinking even if we find a way to trigger the situation on the current gem version, what if in a future version, the error actually is slightly different, and maybe doesn't trigger in the same way, the dd-trace-rb test may start passing for the wrong reasons (doesn't break -- but perhaps not because the code isn't testing for nil). TL;DR My suggestion here is moving away from integration testing and into a simpler unit test: one that directly tests |
What does this PR do?
Adds a pre-condition check in
Datadog::Tracing::Contrib::GraphQL#serialize_error_locationsto handle the case when the provided argumentlocationsisnil.Motivation:
The logic in
contrib/graphql/unified_trace.rbassumes (here) thatlocationis always present in the Hash returned by::GraphQL::Error#to_h, but in reality is only present when if the error can be associated to an AST node (ref). This results in occasionalNoMethodErrors being raised by applications using this gem.Change log entry
N/A — I am not a Datadog employee.
Additional Notes:
Stack Trace:
How to test the change?
I was expecting
bundle exec rake test:graphqlto cover the code changes made incontrib/graphql/unified_trace.rb, but it looks like that's not the case. Any suggestions on how to proceed or how to add the necessary code coverage are very welcome!