File tree Expand file tree Collapse file tree 5 files changed +21
-16
lines changed
Expand file tree Collapse file tree 5 files changed +21
-16
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @segment/analytics-next ' : patch
3+ ---
4+
5+ Remove remote metrics from context and move to stats
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
2525import { popSnippetWindowBuffer } from '../core/buffer/snippet'
2626import { ClassicIntegrationSource } from '../plugins/ajs-destination/types'
2727import { attachInspector } from '../core/inspector'
28+ import { Stats } from '../core/stats'
2829
2930export interface LegacyIntegrationConfiguration {
3031 /* @deprecated - This does not indicate browser types anymore */
@@ -279,7 +280,7 @@ async function loadAnalytics(
279280
280281 const plugins = settings . plugins ?? [ ]
281282 const classicIntegrations = settings . classicIntegrations ?? [ ]
282- Context . initRemoteMetrics ( legacySettings . metrics )
283+ Stats . initRemoteMetrics ( legacySettings . metrics )
283284
284285 // needs to be flushed before plugins are registered
285286 flushPreBuffer ( analytics , preInitBuffer )
Original file line number Diff line number Diff line change @@ -7,20 +7,15 @@ import {
77} from '@segment/analytics-core'
88import { SegmentEvent } from '../events/interfaces'
99import { Stats } from '../stats'
10- import { MetricsOptions , RemoteMetrics } from '../stats/remote-metrics'
11-
12- let _remoteMetrics : RemoteMetrics
1310
1411export class Context extends CoreContext < SegmentEvent > {
1512 static override system ( ) {
1613 return new this ( { type : 'track' , event : 'system' } )
1714 }
18- static initRemoteMetrics ( options ?: MetricsOptions ) {
19- _remoteMetrics = new RemoteMetrics ( options )
20- }
2115 constructor ( event : SegmentEvent , id ?: string ) {
22- super ( event , id , new Stats ( _remoteMetrics ) )
16+ super ( event , id , new Stats ( ) )
2317 }
2418}
19+
2520export { ContextCancelation }
2621export type { ContextFailedDelivery , SerializedContext , CancelationOptions }
Original file line number Diff line number Diff line change 1- import { Stats } from '..'
21import { RemoteMetrics } from '../remote-metrics'
2+ import { Stats } from '..'
3+
4+ const spy = jest . spyOn ( RemoteMetrics . prototype , 'increment' )
35
46describe ( Stats , ( ) => {
57 test ( 'forwards increments to remote metrics endpoint' , ( ) => {
6- const remote = new RemoteMetrics ( )
7- const spy = jest . spyOn ( remote , 'increment' )
8+ Stats . initRemoteMetrics ( )
89
9- const stats = new Stats ( remote )
10+ const stats = new Stats ( )
1011 stats . increment ( 'banana' , 1 , [ 'phone:1' ] )
1112
1213 expect ( spy ) . toHaveBeenCalledWith ( 'banana' , [ 'phone:1' ] )
Original file line number Diff line number Diff line change 11import { CoreStats } from '@segment/analytics-core'
2- import type { RemoteMetrics } from './remote-metrics'
2+ import { MetricsOptions , RemoteMetrics } from './remote-metrics'
3+
4+ let remoteMetrics : RemoteMetrics | undefined
35
46export class Stats extends CoreStats {
5- constructor ( private _remoteMetrics ?: RemoteMetrics ) {
6- super ( )
7+ static initRemoteMetrics ( options ?: MetricsOptions ) {
8+ remoteMetrics = new RemoteMetrics ( options )
79 }
10+
811 override increment ( metric : string , by ?: number , tags ?: string [ ] ) : void {
912 super . increment ( metric , by , tags )
10- this . _remoteMetrics ?. increment ( metric , tags ?? [ ] )
13+ remoteMetrics ?. increment ( metric , tags ?? [ ] )
1114 }
1215}
You can’t perform that action at this time.
0 commit comments