UNPKG

@paychex/instrumentation-document-load

Version:
72 lines 3.08 kB
"use strict"; /* * Copyright The OpenTelemetry Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 = () => { var _a, _b; const entries = {}; const performanceNavigationTiming = (_b = (_a = core_1.otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, '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) => { var _a, _b; const performancePaintTiming = (_b = (_a = core_1.otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, '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