UNPKG

@embrace-io/web-sdk

Version:
1 lines 2.4 kB
{"version":3,"file":"utils.cjs","names":["PerformanceTimingNames"],"sources":["../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/utils.ts"],"sourcesContent":["/*\n * Adapted from OpenTelemetry document-load instrumentation\n * https://github.com/open-telemetry/opentelemetry-js-contrib/tree/cc7eff47e2e7bad7678241b766753d5bd6dbc85f/packages/instrumentation-document-load\n */\n\nimport type { Span } from '@opentelemetry/api';\nimport type { PerformanceEntries } from '@opentelemetry/sdk-trace-web';\nimport { hasKey, PerformanceTimingNames } from '@opentelemetry/sdk-trace-web';\nimport type { PerformanceManager } from '../../../utils/index.ts';\nimport { EventNames } from './enums/EventNames.ts';\n\nexport const getPerformanceNavigationEntries = (): PerformanceEntries => {\n const entries: PerformanceEntries = {};\n const performanceNavigationTiming =\n window.performance.getEntriesByType('navigation')[0];\n\n const keys = Object.values(PerformanceTimingNames);\n keys.forEach((key: PerformanceTimingNames) => {\n if (hasKey(performanceNavigationTiming, key)) {\n const value = performanceNavigationTiming[key];\n if (typeof value === 'number') {\n entries[key] = value;\n }\n }\n });\n\n return entries;\n};\n\nconst performancePaintNames = {\n 'first-paint': EventNames.FIRST_PAINT,\n 'first-contentful-paint': EventNames.FIRST_CONTENTFUL_PAINT,\n};\n\nexport const addSpanPerformancePaintEvents = (\n span: Span,\n perf: PerformanceManager,\n) => {\n const performancePaintTiming = window.performance.getEntriesByType('paint');\n performancePaintTiming.forEach(({ name, startTime }) => {\n if (hasKey(performancePaintNames, name)) {\n span.addEvent(\n performancePaintNames[name],\n perf.epochMillisFromOrigin(startTime),\n );\n }\n });\n};\n"],"mappings":";;;;AAWA,MAAa,wCAA4D;CACvE,MAAM,UAA8B,CAAC;CACrC,MAAM,8BACJ,OAAO,YAAY,iBAAiB,YAAY,CAAC,CAAC;CAGpD,OADoB,OAAOA,6BAAAA,sBACxB,CAAC,CAAC,SAAS,QAAgC;EAC5C,KAAA,GAAA,6BAAA,OAAA,CAAW,6BAA6B,GAAG,GAAG;GAC5C,MAAM,QAAQ,4BAA4B;GAC1C,IAAI,OAAO,UAAU,UACnB,QAAQ,OAAO;EAEnB;CACF,CAAC;CAED,OAAO;AACT;AAEA,MAAM,wBAAwB;CAC5B,eAAA;CACA,0BAAA;AACF;AAEA,MAAa,iCACX,MACA,SACG;CAEH,OADsC,YAAY,iBAAiB,OAC9C,CAAC,CAAC,SAAS,EAAE,MAAM,gBAAgB;EACtD,KAAA,GAAA,6BAAA,OAAA,CAAW,uBAAuB,IAAI,GACpC,KAAK,SACH,sBAAsB,OACtB,KAAK,sBAAsB,SAAS,CACtC;CAEJ,CAAC;AACH"}