Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: segmentio/analytics-next
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 22319533901effe22e1892ed5c607cdef0bebf61
Choose a base ref
..
head repository: segmentio/analytics-next
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 285e3ed5f607ecac1042c87161871b5bea2b2487
Choose a head ref
Showing with 15 additions and 6 deletions.
  1. +4 −0 packages/browser/CHANGELOG.md
  2. +4 −1 packages/browser/src/core/stats/__tests__/remote-metrics.test.ts
  3. +7 −5 packages/browser/src/core/stats/remote-metrics.ts
4 changes: 4 additions & 0 deletions packages/browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@

- [#573](https://github.com/segmentio/analytics-next/pull/573) [`6203c20`](https://github.com/segmentio/analytics-next/commit/6203c20cd0673f55a29c546440e0c02f6998df5a) Thanks [@arielsilvestri](https://github.com/arielsilvestri)! - Enhances console error logging when requests to settings api fail

### Patch Changes

- [#582](https://github.com/segmentio/analytics-next/pull/582) [`ebafece`](https://github.com/segmentio/analytics-next/commit/ebafeceb5e3b2c6cfe3d29313a443615093170a2) Thanks [@chrisradek](https://github.com/chrisradek)! - Updates error message when sending metrics fails to indicate that metrics failed to send.

## 1.42.3

### Patch Changes
Original file line number Diff line number Diff line change
@@ -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 () => {
12 changes: 7 additions & 5 deletions packages/browser/src/core/stats/remote-metrics.ts
Original file line number Diff line number Diff line change
@@ -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
})
}