@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
39 lines • 2.18 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.observePerformanceWithTraceManager = exports.getBestSupportedEntryTypes = void 0;
const getSpanFromPerformanceEntry_1 = require("./getSpanFromPerformanceEntry");
const getBestSupportedEntryTypes = () => (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')
? PerformanceObserver.supportedEntryTypes.filter((entryType) => entryType !== 'longtask')
: PerformanceObserver.supportedEntryTypes);
exports.getBestSupportedEntryTypes = getBestSupportedEntryTypes;
/**
* The function creates an instance of PerformanceObserver that integrates with a TraceManager to automatically observe
* and map specified types of performance entries from the browser's Performance API to trace entries.
* @param traceManager - An instance of TraceManager
* that will handle the processing
* of mapped performance entries.
* @param entryTypes - An array of strings specifying the types of
* performance entries to observe (e.g.,
* ["resource", "navigation"]).
*
* @returns A cleanup function that, when called, disconnects the
* PerformanceObserver, stopping the observation of
* performance entries.
*/
const observePerformanceWithTraceManager = ({ traceManager, deriveRelationFromPerformanceEntry, entryTypes = (0, exports.getBestSupportedEntryTypes)(), keep, }) => {
const observer = new PerformanceObserver((entryList) => {
entryList.getEntries().forEach((entry) => {
if (keep !== undefined && !keep(entry)) {
return;
}
const traceEntry = (0, getSpanFromPerformanceEntry_1.getSpanFromPerformanceEntry)(entry, deriveRelationFromPerformanceEntry);
if (traceEntry !== undefined) {
traceManager.processSpan(traceEntry);
}
});
});
observer.observe({ entryTypes });
return () => void observer.disconnect();
};
exports.observePerformanceWithTraceManager = observePerformanceWithTraceManager;
//# sourceMappingURL=observePerformanceWithTraceManager.js.map
;