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
(Unstable) server-side network request debug route #1284
Conversation
* Undo changes in demo-store * Undo changes in remix-oxygen to prevent having multiple request-id * Undo changes in hydrogen storefront client * Move request logging logic to CLI * Ensure there is a request-id and log parent request event in CLI * Log sub request event using a global fetch stub * Send server events from the CLI realm instead of the app * Refactor server events * Refactor code to use defaultDispatcher from MiniOxygen * Rely on AsyncLocalStorage to handle ids to support requests to 3p APIs * Cleanup * Update to MiniOxygen 2.2.0 to use globalFetch and onRequest * Fix queryName for mock.shop * Fix types
This comment has been minimized.
This comment has been minimized.
@frandiox I realized that the CLI path doesn't pick up the request to cache api. Any way we can patch cache api to get these network requests? |
Co-authored-by: Helen Lin <helen.lin@shopify.com>
@frandiox Do we need to pass around the |
packages/remix-oxygen/src/server.ts
Outdated
globalThis.__H2O_LOG_EVENT = createEventLogger(context); | ||
globalThis.__H2O_LOG_EVENT = createEventLogger(context, { | ||
requestId: request.headers.get('request-id'), | ||
purpose: request.headers.get('purpose'), | ||
}); |
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.
@wizardlyhel The problem with this approach is that we are now leaking the request-id to the global scope. This works fine if you only have 1 tab open or only hover 1 thing at a time. The moment you have 2 parallel requests or more, it starts overwriting the request-id in the global scope and it won't be deterministic which id is used for sub-requests.
That's what AsyncLocalStorage was preventing. And also why I think we should pass this info down from createStorefrontClient
and createWithCache
somehow if we want it to work in prod eventually without AsyncLocalStorage.
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.
Oh good point - forgot about multiple request problem
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.
We already have that request-id
in createStorefrontClient
just isn't passed down all the way to where we are handling cache logging. If we want it also with createWithCache
, then it would also needs to be passed down.
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.
I've changed flame-cart-js
dependency to be downloaded via CDN in the browser directly to avoid increasing the size of the CLI installation. Hope that's ok.
Aside from that, I'm finding that a lot of requests are missing from the events. This wasn't happening yesterday so it might be related to recent changes? Here's missing most of the requests, including MISS/HIT/STALE (this is the home page of skeleton template so it should have more requests).
Also, check the comment about AsyncLocalStorage, it might be related to this issue.
The problem with this approach is that we are now leaking the request-id to the global scope. This works fine if you only have 1 tab open but the moment you have 2 parallel requests or more, it starts overwriting the request-id to the global scope and it won't be deterministic which id is used for sub-requests.
That's what AsyncLocalStorage was preventing. And also why I think we should pass this info down from createStorefrontClient and createWithCache somehow if we want it to work in prod eventually without AsyncLocalStorage.
@wizardlyhel so the interval wasn't working properly. I've replaced it with an event emitter and now there are no more missing events 🎉 Also, you can now open multiple tabs on the
If the user didn't pass |
@frandiox Thanks for the interval update. I didn't know there is a different way we can send messages. As for
Optional for now. Calendar release required.
Awesome |
@frandiox Do you think we need to bring back |
@wizardlyhel I was tinkering with globalFetch quite a lot and concluded that for now we should forget about it. The reasons:
There might be workarounds and perhaps we can revisit this at some point but for now I think it's a good call to skip raw fetch 👍 |
WHAT is this pull request doing?
(Unstable) A new virtual route that logs the network requests happening at the server side.
Features
<cache status> <purpose?> <url>
<cache status> <purpose?> <query name>
Known issues
npm run dev
will fix thisHow to test
After running
npm run dev
in a project, you should seeOpen http://localhost:3000/debug-network
Clicking on the link will open http://localhost:3000 in another tab.
Navigate around the app and you should see server-side network requests being logged in the network flame graph
Post-merge steps
Checklist