-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby): fix broken GraphQL resolver tracing #29015
Conversation
Oh yeah we discussed this the other day. The fix is good but the timing will probably be very off since it would encompass anything that happens while the thread is suspended. Anyways, good fix. |
return result | ||
} | ||
|
||
const endActivity = (): void => { | ||
if (activity) { |
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.
This can be dropped since we test and shortcut return above
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.
Typescript disagrees.
This file has incomplete typings but if I add proper typings to activity
and remove this check I get TS error: TS2339: Property 'end' does not exist on type 'void | IActivity'. Property 'end' does not exist on type 'void'.
if (activity) { | ||
activity.end() | ||
} | ||
} | ||
if (typeof result?.then === `function`) { | ||
result.then(endActivity, endActivity) |
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.
While this won't swallow the error, I think it will suppress nodejs' builtin reporting for uncaught promises (right? because it sees the error is handled at least somewhere)
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.
No, it's a different promise chain than the one returned. So it is not affecting unhandled rejections. Also double-checked with this example in node:
const foo = new Promise(function (resolve, reject) {
setTimeout(() => {
reject(new Error("Err"));
}, 1000);
});
const func = () => {};
foo.then(func, func);
foo.then(() => { console.log(`test`); });
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.
🚢
Description
Our resolver tracing is broken ATM. Tracing simply counts sync resolver call. It doesn't await the returned promise and ends the activity immediately. So it kinda tracks sync resolvers but not async.
With this change, we track correctly in both cases.