UNPKG

@zendesk/react-measure-timing-hooks

Version:

react hooks for measuring time to interactive and time to render of components

69 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSpanFromPerformanceEntry = getSpanFromPerformanceEntry; const ensureTimestamp_1 = require("./ensureTimestamp"); const getCommonUrlForTracing_1 = require("./getCommonUrlForTracing"); /** * Maps Performance Entry to a Span * @returns The span. */ function getSpanFromPerformanceEntry(inputEntry, deriveRelationFromPerformanceEntry) { // react in dev mode generates hundreds of these marks, ignore them if (inputEntry.entryType === 'mark' && inputEntry.name.startsWith('--')) { return undefined; } const attributes = 'detail' in inputEntry && typeof inputEntry.detail === 'object' && inputEntry.detail !== null ? inputEntry.detail : {}; const type = inputEntry.entryType; const relatedTo = deriveRelationFromPerformanceEntry?.(inputEntry); let { name } = inputEntry; if (type === 'resource' || type === 'navigation') { const { commonUrl, query, hash } = (0, getCommonUrlForTracing_1.getCommonUrlForTracing)(inputEntry.name); name = commonUrl; // write a function in lotus to extract from datadog's SDK rather than hardcoding the implementation if (type === 'resource') { const resourceTiming = inputEntry; return { type: 'resource', name, startTime: (0, ensureTimestamp_1.ensureTimestamp)({ now: inputEntry.startTime }), attributes, duration: inputEntry.duration, // status, performanceEntry: inputEntry, resourceDetails: { initiatorType: resourceTiming.initiatorType, query, hash, }, relatedTo, }; } } else if (type !== 'mark' && type !== 'measure') { name = `${type}${inputEntry.name && inputEntry.name !== 'unknown' && inputEntry.name.length > 0 && type !== inputEntry.name ? `/${inputEntry.name}` : ''}`; } const timestamp = { now: inputEntry.startTime, }; const traceEntry = { type, name, startTime: (0, ensureTimestamp_1.ensureTimestamp)(timestamp), attributes, duration: inputEntry.duration, // status, performanceEntry: inputEntry, relatedTo, }; return traceEntry; } //# sourceMappingURL=getSpanFromPerformanceEntry.js.map