{"version":3,"file":"performanceObserver.cjs","names":[],"sources":["../../../src/utils/performanceObserver/performanceObserver.ts"],"sourcesContent":["import type { DiagLogger } from '@opentelemetry/api';\n\nexport function isEntryTypeSupported(type: string): boolean {\n  return (\n    typeof PerformanceObserver !== 'undefined' &&\n    (PerformanceObserver.supportedEntryTypes?.includes(type) ?? false)\n  );\n}\n\n/**\n * Creates a PerformanceObserver for the specified entry type if supported, and starts observing.\n * Returns the observer instance, or null if the entry type is not supported or if an error occurs.\n *\n * Each entry is passed individually to `processEntry`. Errors thrown by `processEntry` are caught\n * and logged via `diag` (if provided) so that one bad entry does not block the rest.\n *\n * Note: The observer is created with the \"buffered\" option set to true, so it will receive entries\n * that were recorded before the observer was created.\n * buffered: true is not supported when observing multiple entry types, so if you need to observe\n * multiple types, you should create separate observers for each type with buffered: true.\n * See https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/observe#entrytypes\n */\nexport function createPerformanceObserver<T extends PerformanceEntry>(\n  type: string,\n  processEntry: (entry: T) => void,\n  options?: PerformanceObserverInit & { diag?: DiagLogger },\n): PerformanceObserver | null {\n  const { diag, ...observeOptions } = options ?? {};\n\n  if (!isEntryTypeSupported(type)) {\n    diag?.debug(`${type} not supported, skipping observer`);\n    return null;\n  }\n\n  try {\n    const observer = new PerformanceObserver((list) => {\n      for (const entry of list.getEntries() as T[]) {\n        try {\n          processEntry(entry);\n        } catch (e) {\n          diag?.error(`error processing ${type} entry`, e);\n        }\n      }\n    });\n    observer.observe({ type, buffered: true, ...observeOptions });\n    return observer;\n  } catch {\n    return null;\n  }\n}\n"],"mappings":";;AAEA,SAAgB,qBAAqB,MAAuB;AAC1D,QACE,OAAO,wBAAwB,gBAC9B,oBAAoB,qBAAqB,SAAS,KAAK,IAAI;;;;;;;;;;;;;;;AAiBhE,SAAgB,0BACd,MACA,cACA,SAC4B;CAC5B,MAAM,EAAE,MAAM,GAAG,mBAAmB,WAAW,EAAE;AAEjD,KAAI,CAAC,qBAAqB,KAAK,EAAE;AAC/B,QAAM,MAAM,GAAG,KAAK,mCAAmC;AACvD,SAAO;;AAGT,KAAI;EACF,MAAM,WAAW,IAAI,qBAAqB,SAAS;AACjD,QAAK,MAAM,SAAS,KAAK,YAAY,CACnC,KAAI;AACF,iBAAa,MAAM;YACZ,GAAG;AACV,UAAM,MAAM,oBAAoB,KAAK,SAAS,EAAE;;IAGpD;AACF,WAAS,QAAQ;GAAE;GAAM,UAAU;GAAM,GAAG;GAAgB,CAAC;AAC7D,SAAO;SACD;AACN,SAAO"}