Skip to content

Commit

Permalink
Rename TTFBAttribution fields from *Time to *Duration (#453)
Browse files Browse the repository at this point in the history
* Rename TTFBAttribution fields to duration

* Update README

* Update src/types/ttfb.ts

Co-authored-by: Rick Viscomi <rviscomi@users.noreply.github.com>

---------

Co-authored-by: Rick Viscomi <rviscomi@users.noreply.github.com>
  • Loading branch information
philipwalton and rviscomi authored Apr 1, 2024
1 parent c963a57 commit 372598a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
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
* 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

0 comments on commit 372598a

Please sign in to comment.