Skip to content
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

Rename TTFBAttribution fields from *Time to *Duration #453

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1028,21 +1028,21 @@ interface TTFBAttribution {
* DNS lookup begins. This includes redirects, service worker startup, and
* HTTP cache lookup times.
*/
waitingTime: number;
waitingDuration: number;
/**
* The total time to resolve the DNS for the current request.
*/
dnsTime: number;
dnsDuration: number;
/**
* The total time to create the connection to the requested domain.
*/
connectionTime: number;
connectionDuration: number;
/**
* The time time from when the request was sent until the first byte of the
philipwalton marked this conversation as resolved.
Show resolved Hide resolved
* response was received. This includes network time as well as server
* processing time.
*/
requestTime: number;
requestDuration: number;
/**
* The `navigation` entry of the current page, which is useful for diagnosing
* general page load issues. This can be used to access `serverTiming` for example:
Expand Down
16 changes: 8 additions & 8 deletions src/attribution/onTTFB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ const attributeTTFB = (metric: TTFBMetric): void => {
);

(metric as TTFBMetricWithAttribution).attribution = {
waitingTime: dnsStart,
dnsTime: connectStart - dnsStart,
connectionTime: requestStart - connectStart,
requestTime: metric.value - requestStart,
waitingDuration: dnsStart,
dnsDuration: connectStart - dnsStart,
connectionDuration: requestStart - connectStart,
requestDuration: metric.value - requestStart,
navigationEntry: navigationEntry,
};
return;
}
// Set an empty object if no other attribution has been set.
(metric as TTFBMetricWithAttribution).attribution = {
waitingTime: 0,
dnsTime: 0,
connectionTime: 0,
requestTime: 0,
waitingDuration: 0,
dnsDuration: 0,
connectionDuration: 0,
requestDuration: 0,
};
};

Expand Down
10 changes: 5 additions & 5 deletions src/types/ttfb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ export interface TTFBAttribution {
* DNS lookup begins. This includes redirects, service worker startup, and
* HTTP cache lookup times.
*/
waitingTime: number;
waitingDuration: number;
/**
* The total time to resolve the DNS for the current request.
*/
dnsTime: number;
dnsDuration: number;
/**
* The total time to create the connection to the requested domain.
*/
connectionTime: number;
connectionDuration: number;
/**
* The time time from when the request was sent until the first byte of the
* The total time from when the request was sent until the first byte of the
* response was received. This includes network time as well as server
* processing time.
*/
requestTime: number;
requestDuration: number;
/**
* The `navigation` entry of the current page, which is useful for diagnosing
* general page load issues. This can be used to access `serverTiming` for example:
Expand Down
24 changes: 12 additions & 12 deletions test/e2e/onTTFB-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,19 @@ describe('onTTFB()', async function () {

const navEntry = ttfb.entries[0];
assert.strictEqual(
ttfb.attribution.waitingTime,
ttfb.attribution.waitingDuration,
navEntry.domainLookupStart,
);
assert.strictEqual(
ttfb.attribution.dnsTime,
ttfb.attribution.dnsDuration,
navEntry.connectStart - navEntry.domainLookupStart,
);
assert.strictEqual(
ttfb.attribution.connectionTime,
ttfb.attribution.connectionDuration,
navEntry.requestStart - navEntry.connectStart,
);
assert.strictEqual(
ttfb.attribution.requestTime,
ttfb.attribution.requestDuration,
navEntry.responseStart - navEntry.requestStart,
);

Expand Down Expand Up @@ -303,22 +303,22 @@ describe('onTTFB()', async function () {

const navEntry = ttfb.entries[0];
assert.strictEqual(
ttfb.attribution.waitingTime,
ttfb.attribution.waitingDuration,
Math.max(0, navEntry.domainLookupStart - activationStart),
);
assert.strictEqual(
ttfb.attribution.dnsTime,
ttfb.attribution.dnsDuration,
Math.max(0, navEntry.connectStart - activationStart) -
Math.max(0, navEntry.domainLookupStart - activationStart),
);
assert.strictEqual(
ttfb.attribution.connectionTime,
ttfb.attribution.connectionDuration,
Math.max(0, navEntry.requestStart - activationStart) -
Math.max(0, navEntry.connectStart - activationStart),
);

assert.strictEqual(
ttfb.attribution.requestTime,
ttfb.attribution.requestDuration,
Math.max(0, navEntry.responseStart - activationStart) -
Math.max(0, navEntry.requestStart - activationStart),
);
Expand Down Expand Up @@ -346,10 +346,10 @@ describe('onTTFB()', async function () {
assert.strictEqual(ttfb.navigationType, 'back-forward-cache');
assert.strictEqual(ttfb.entries.length, 0);

assert.strictEqual(ttfb.attribution.waitingTime, 0);
assert.strictEqual(ttfb.attribution.dnsTime, 0);
assert.strictEqual(ttfb.attribution.connectionTime, 0);
assert.strictEqual(ttfb.attribution.requestTime, 0);
assert.strictEqual(ttfb.attribution.waitingDuration, 0);
assert.strictEqual(ttfb.attribution.dnsDuration, 0);
assert.strictEqual(ttfb.attribution.connectionDuration, 0);
assert.strictEqual(ttfb.attribution.requestDuration, 0);
assert.strictEqual(ttfb.attribution.navigationEntry, undefined);
});
});
Expand Down
Loading