Skip to content
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions packages/tracing/src/browser/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ export class MetricsInstrumentation {
return;
}

const timeOrigin = msToSec(performance.timeOrigin);
const startTime = msToSec(entry.startTime as number);
logger.log('[Measurements] Adding LCP');
this._measurements['lcp'] = { value: metric.value };
this._measurements['mark.lcp'] = { value: timeOrigin + startTime };
if (browserPerformanceTimeOrigin !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browserPerformanceTimeOrigin should always exist when we can actually report LCP and FID.

I'd just replace performance.timeOrigin above with browserPerformanceTimeOrigin.

I see we use performance.timeOrigin directly in ember... maybe we change that too, cc @k-fish.

performance.measure && performance.getEntriesByName && performance.timeOrigin !== undefined;

const startTimestamp = (measure.startTime + performance.timeOrigin) / 1000;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhcarvalho typescript told me that browserPerformanceTimeOrigin could be undefined, but I'll coerce it as a number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah typescript... it is only undefined if performance is also undefined.

const timeOrigin = msToSec(browserPerformanceTimeOrigin);
this._measurements['mark.lcp'] = { value: timeOrigin + startTime };
}
});
}

Expand All @@ -253,11 +255,13 @@ export class MetricsInstrumentation {
return;
}

const timeOrigin = msToSec(performance.timeOrigin);
const startTime = msToSec(entry.startTime as number);
logger.log('[Measurements] Adding FID');
this._measurements['fid'] = { value: metric.value };
this._measurements['mark.fid'] = { value: timeOrigin + startTime };
if (browserPerformanceTimeOrigin !== undefined) {
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
this._measurements['mark.fid'] = { value: timeOrigin + startTime };
}
});
}

Expand Down