Repository navigation
feat(fetch): expose timings #32647
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
feat(fetch): expose timings #32647
Changes from 2 commits
8de8383
819e0a5
7a251be
b717257
b1d523b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,14 +422,35 @@ export abstract class APIRequestContext extends SdkObject { | |
|
|
||
| const chunks: Buffer[] = []; | ||
| const notifyBodyFinished = () => { | ||
| function relativeTime(time: number | undefined): number { | ||
| if (!time) | ||
| return -1; | ||
| return time - startAt; | ||
| } | ||
| const endAt = monotonicTime(); | ||
| // spec: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming | ||
| const timing: channels.ResourceTiming = { | ||
| startTime: startAt, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs say
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in b717257 |
||
| domainLookupStart: dnsLookupAt ? 0 : -1, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why zero and not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understand is that the browser has some other steps like cache resolution before the DNS lookup, so there might be time between startTime and the DNS lookup start. On Node.js, I don't think there's anything between that - so it's zero, because we know the DNS lookup happens immediately after the request start. |
||
| domainLookupEnd: dnsLookupAt ? dnsLookupAt! - startAt : -1, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in b1d523b |
||
| connectStart: dnsLookupAt ? dnsLookupAt! - startAt : 0, | ||
| secureConnectionStart: dnsLookupAt ? dnsLookupAt! - startAt : 0, | ||
| connectEnd: relativeTime(tlsHandshakeAt ?? tcpConnectionAt), | ||
| requestStart: relativeTime(tlsHandshakeAt ?? tcpConnectionAt), | ||
| responseStart: responseAt - startAt, | ||
| }; | ||
| const responseEndTiming = endAt - startAt; | ||
|
|
||
| const body = Buffer.concat(chunks); | ||
| notifyRequestFinished(body); | ||
| fulfill({ | ||
| url: response.url || url.toString(), | ||
| status: response.statusCode || 0, | ||
| statusText: response.statusMessage || '', | ||
| headers: toHeadersArray(response.rawHeaders), | ||
| body | ||
| body, | ||
| timing, | ||
| responseEndTiming, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have two sets of timings now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For browser requests, most of the timings are transmitted in the I thought about amending the |
||
| }); | ||
| }; | ||
|
|
||
|
|
@@ -483,6 +504,9 @@ export abstract class APIRequestContext extends SdkObject { | |
| socket.on('lookup', () => { dnsLookupAt = monotonicTime(); }); | ||
| socket.on('connect', () => { tcpConnectionAt = monotonicTime(); }); | ||
| socket.on('secureConnect', () => { tlsHandshakeAt = monotonicTime(); }); | ||
|
|
||
| // socks / http proxy | ||
| socket.on('proxyConnect', () => { tcpConnectionAt = monotonicTime(); }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding timings to the protocol uncovered that |
||
| }); | ||
| request.on('finish', () => { requestFinishAt = monotonicTime(); }); | ||
|
|
||
|
|
||
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 is a drive-by fix - pretty sure it shouldn't say "start the domain name lookup"