diff --git a/CHANGELOG.md b/CHANGELOG.md index 4872f2bc0b16..2dd69981bc3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott - [apm] fix: Use Performance API for timings when available, including Web Workers (#2492) +- [apm] fix: Remove Performance references (#2495) ## 5.14.1 diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 0c6e1dc6bbf2..a2541549afab 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -349,7 +349,18 @@ function _htmlElementAsString(el: unknown): string { const INITIAL_TIME = Date.now(); let prevNow = 0; -const performanceFallback: Pick = { +/** + * Cross platform compatible partial performance implementation + */ +interface CrossPlatformPerformance { + /** + * Returns the current timestamp in ms + */ + now(): number; + timeOrigin: number; +} + +const performanceFallback: CrossPlatformPerformance = { now(): number { let now = Date.now() - INITIAL_TIME; if (now < prevNow) { @@ -361,10 +372,10 @@ const performanceFallback: Pick = { timeOrigin: INITIAL_TIME, }; -export const crossPlatformPerformance: Pick = (() => { +export const crossPlatformPerformance: CrossPlatformPerformance = (() => { if (isNodeEnv()) { try { - const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: Performance }; + const perfHooks = dynamicRequire(module, 'perf_hooks') as { performance: CrossPlatformPerformance }; return perfHooks.performance; } catch (_) { return performanceFallback;