From d12586a48eb23e7bcc1af458fae8963a3d13c2b7 Mon Sep 17 00:00:00 2001 From: Christopher Radek Date: Thu, 11 Aug 2022 15:31:42 -0700 Subject: [PATCH 1/2] improve error message when sending metrics fails --- .../src/core/stats/__tests__/remote-metrics.test.ts | 5 ++++- packages/browser/src/core/stats/remote-metrics.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts b/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts index d0c00cd2d..f724aeb8d 100644 --- a/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts +++ b/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts @@ -118,7 +118,10 @@ describe('remote metrics', () => { remote.increment('analytics_js.banana', ['phone:1']) await remote.flush() - expect(errorSpy).toHaveBeenCalledWith(error) + expect(errorSpy).toHaveBeenCalledWith( + 'Error sending segment performance metrics', + error + ) }) test('disables metrics reporting in case of errors', async () => { diff --git a/packages/browser/src/core/stats/remote-metrics.ts b/packages/browser/src/core/stats/remote-metrics.ts index f71f2a532..8c71b7068 100644 --- a/packages/browser/src/core/stats/remote-metrics.ts +++ b/packages/browser/src/core/stats/remote-metrics.ts @@ -11,6 +11,10 @@ export interface MetricsOptions { type Metric = { type: 'Counter'; metric: string; value: number; tags: object } +function logError(err: unknown): void { + console.error('Error sending segment performance metrics', err) +} + export class RemoteMetrics { private host: string private flushTimer: number @@ -36,9 +40,7 @@ export class RemoteMetrics { } flushing = true - this.flush().catch((err) => { - console.error(err) - }) + this.flush().catch(logError) flushing = false @@ -90,7 +92,7 @@ export class RemoteMetrics { }) if (metric.includes('error')) { - this.flush().catch((err) => console.error(err)) + this.flush().catch(logError) } } @@ -100,7 +102,7 @@ export class RemoteMetrics { } await this.send().catch((error) => { - console.error(error) + logError(error) this.sampleRate = 0 }) } From c876aa1f3abb97df4c7419e0b0040204a687521a Mon Sep 17 00:00:00 2001 From: Christopher Radek Date: Thu, 11 Aug 2022 15:34:27 -0700 Subject: [PATCH 2/2] add changelog --- .changeset/moody-rats-double.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/moody-rats-double.md diff --git a/.changeset/moody-rats-double.md b/.changeset/moody-rats-double.md new file mode 100644 index 000000000..cfab3e79b --- /dev/null +++ b/.changeset/moody-rats-double.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-next': patch +--- + +Updates error message when sending metrics fails to indicate that metrics failed to send.