@embrace-io/web-sdk
Version:
44 lines (43 loc) • 1.77 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/utils/PerformanceManager/OTelPerformanceManager.ts
let _zeroTimeMillis;
function updateZeroTimeMillis(epochMs) {
_zeroTimeMillis = epochMs;
}
function _resetZeroTimeMillisForTesting() {
_zeroTimeMillis = void 0;
}
var OTelPerformanceManager = class {
_clock;
navigationEntry = null;
constructor(clock = window.performance) {
this._clock = clock;
}
epochMillisFromOrigin = (originOffset) => this._clock.timeOrigin + originOffset;
getNowMillis = () => this.epochMillisFromOrigin(this._clock.now());
/**
* To measure the way a user experienced a metric, we measure metrics relative to the time the user
* started viewing the current page or view. On prerendered pages, this is activationStart. On bfcache
* restores and soft navigations, this is the time of the restore or navigation. On all other pages
* this value will be zero.
*/
getZeroTime = () => Math.max(this._clock.timeOrigin + this._getNavigationActivationStart(), _zeroTimeMillis ?? 0);
_getNavigationEntry() {
if (this.navigationEntry) return this.navigationEntry;
const [entry] = this._clock.getEntriesByType?.("navigation") ?? [];
if (entry) {
this.navigationEntry = entry;
return this.navigationEntry;
}
return null;
}
_getNavigationActivationStart() {
return this._getNavigationEntry()?.activationStart ?? 0;
}
millisFromZeroTime = (originOffset) => Math.max(0, originOffset - (this.getZeroTime() - this._clock.timeOrigin));
};
//#endregion
exports.OTelPerformanceManager = OTelPerformanceManager;
exports._resetZeroTimeMillisForTesting = _resetZeroTimeMillisForTesting;
exports.updateZeroTimeMillis = updateZeroTimeMillis;
//# sourceMappingURL=OTelPerformanceManager.cjs.map