Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error message when sending metrics fails #582

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-rats-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Updates error message when sending metrics fails to indicate that metrics failed to send.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
12 changes: 7 additions & 5 deletions packages/browser/src/core/stats/remote-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,9 +40,7 @@ export class RemoteMetrics {
}

flushing = true
this.flush().catch((err) => {
console.error(err)
})
this.flush().catch(logError)

flushing = false

Expand Down Expand Up @@ -90,7 +92,7 @@ export class RemoteMetrics {
})

if (metric.includes('error')) {
this.flush().catch((err) => console.error(err))
this.flush().catch(logError)
}
}

Expand All @@ -100,7 +102,7 @@ export class RemoteMetrics {
}

await this.send().catch((error) => {
console.error(error)
logError(error)
this.sampleRate = 0
})
}
Expand Down