UNPKG

@opentelemetry/instrumentation-document-load

Version:
59 lines 2.4 kB
"use strict"; /* * Copyright The OpenTelemetry Authors * SPDX-License-Identifier: Apache-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.addSpanPerformancePaintEvents = exports.getPerformanceNavigationEntries = void 0; const core_1 = require("@opentelemetry/core"); const sdk_trace_web_1 = require("@opentelemetry/sdk-trace-web"); const EventNames_1 = require("./enums/EventNames"); const getPerformanceNavigationEntries = () => { const entries = {}; const performanceNavigationTiming = core_1.otperformance.getEntriesByType?.('navigation')[0]; if (performanceNavigationTiming) { const keys = Object.values(sdk_trace_web_1.PerformanceTimingNames); keys.forEach((key) => { if ((0, sdk_trace_web_1.hasKey)(performanceNavigationTiming, key)) { const value = performanceNavigationTiming[key]; if (typeof value === 'number') { entries[key] = value; } } }); } else { // // fallback to previous version const perf = core_1.otperformance; const performanceTiming = perf.timing; if (performanceTiming) { const keys = Object.values(sdk_trace_web_1.PerformanceTimingNames); keys.forEach((key) => { if ((0, sdk_trace_web_1.hasKey)(performanceTiming, key)) { const value = performanceTiming[key]; if (typeof value === 'number') { entries[key] = value; } } }); } } return entries; }; exports.getPerformanceNavigationEntries = getPerformanceNavigationEntries; const performancePaintNames = { 'first-paint': EventNames_1.EventNames.FIRST_PAINT, 'first-contentful-paint': EventNames_1.EventNames.FIRST_CONTENTFUL_PAINT, }; const addSpanPerformancePaintEvents = (span) => { const performancePaintTiming = core_1.otperformance.getEntriesByType?.('paint'); if (performancePaintTiming) { performancePaintTiming.forEach(({ name, startTime }) => { if ((0, sdk_trace_web_1.hasKey)(performancePaintNames, name)) { span.addEvent(performancePaintNames[name], startTime); } }); } }; exports.addSpanPerformancePaintEvents = addSpanPerformancePaintEvents; //# sourceMappingURL=utils.js.map