From b0a0cd9fb4c447df2766bb542bad79489608c9c6 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 12 Mar 2020 08:49:02 +0100 Subject: [PATCH 1/4] ref: Use `onresourcetimingbufferfull` --- CHANGELOG.md | 2 ++ packages/apm/src/integrations/tracing.ts | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd0a935195e4..c25fb2d6f3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott +- [apm] ref: Use `onresourcetimingbufferfull` and don't delete measurements + ## 5.14.0 - [apm] feat: Add a simple heartbeat check, if activities don't change in 3 beats, finish the transaction (#2478) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 34b2eb685868..280dfc6a8c2f 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -182,6 +182,20 @@ export class Tracing implements Integration { public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { Tracing._getCurrentHub = getCurrentHub; + if (global.performance) { + // The Performance object has a limited buffer size, often 150 entries. At some point the buffer may overflow, in + // which case we would not be able to use it to create/update spans. + // https://developer.mozilla.org/en-US/docs/Web/API/Performance + const oldCallback = performance.onresourcetimingbufferfull; + performance.onresourcetimingbufferfull = function(_event: unknown): void { + logger.warn('[Tracing]: Resource Timing Buffer is FULL! Increasing it to 300'); + performance.setResourceTimingBufferSize(300); + if (oldCallback) { + oldCallback.apply(this, arguments); + } + }; + } + if (this._emitOptionsWarning) { logger.warn( '[Tracing] You need to define `tracingOrigins` in the options. Set an array of urls or patterns to trace.', @@ -603,14 +617,6 @@ export class Tracing implements Integration { addSpan(evaluation); } - // The Performance object has a limited buffer size, often 150 entries. At some point the buffer may overflow, in - // which case we would not be able to use it to create/update spans. Therefore, after we have processed entries to - // report to Sentry, we clear the buffer in an attempt to allow for more entries to be added in the future. - // https://developer.mozilla.org/en-US/docs/Web/API/Performance - logger.log('[Tracing] Clearing most performance marks'); - performance.clearMarks(); - performance.clearMeasures(); - performance.clearResourceTimings(); Tracing._performanceCursor = Math.max(performance.getEntries().length - 1, 0); // tslint:enable: no-unsafe-any From 1a6a4d9ae601ee7c437d7a69989a8638796d49ca Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 12 Mar 2020 09:09:17 +0100 Subject: [PATCH 2/4] ref: Increase buffer *2 --- packages/apm/src/integrations/tracing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 280dfc6a8c2f..5a61b4865b99 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -189,7 +189,7 @@ export class Tracing implements Integration { const oldCallback = performance.onresourcetimingbufferfull; performance.onresourcetimingbufferfull = function(_event: unknown): void { logger.warn('[Tracing]: Resource Timing Buffer is FULL! Increasing it to 300'); - performance.setResourceTimingBufferSize(300); + performance.setResourceTimingBufferSize(Tracing._performanceCursor * 2); if (oldCallback) { oldCallback.apply(this, arguments); } From 142fbb748e161071cf205c18aa905bde0847184b Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 12 Mar 2020 09:12:16 +0100 Subject: [PATCH 3/4] chore: Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c25fb2d6f3c0..ae13304c6aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott -- [apm] ref: Use `onresourcetimingbufferfull` and don't delete measurements +- [apm] ref: Use `onresourcetimingbufferfull` and don't delete measurements (#2490) ## 5.14.0 From 538b60ccfc273c1bfa1a2a0fb026b40e9ac27433 Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 12 Mar 2020 09:41:47 +0100 Subject: [PATCH 4/4] fix: Remove callback --- CHANGELOG.md | 2 +- packages/apm/src/integrations/tracing.ts | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae13304c6aff..1088d95c622b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott -- [apm] ref: Use `onresourcetimingbufferfull` and don't delete measurements (#2490) +- [apm] ref: Remove performance clear entry calls (#2490) ## 5.14.0 diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 5a61b4865b99..7f284e848d5f 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -182,20 +182,6 @@ export class Tracing implements Integration { public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { Tracing._getCurrentHub = getCurrentHub; - if (global.performance) { - // The Performance object has a limited buffer size, often 150 entries. At some point the buffer may overflow, in - // which case we would not be able to use it to create/update spans. - // https://developer.mozilla.org/en-US/docs/Web/API/Performance - const oldCallback = performance.onresourcetimingbufferfull; - performance.onresourcetimingbufferfull = function(_event: unknown): void { - logger.warn('[Tracing]: Resource Timing Buffer is FULL! Increasing it to 300'); - performance.setResourceTimingBufferSize(Tracing._performanceCursor * 2); - if (oldCallback) { - oldCallback.apply(this, arguments); - } - }; - } - if (this._emitOptionsWarning) { logger.warn( '[Tracing] You need to define `tracingOrigins` in the options. Set an array of urls or patterns to trace.',