1
1
import type { Client , ClientOptions , MeasurementUnit , MetricsAggregator , Primitive } from '@sentry/types' ;
2
2
import { timestampInSeconds } from '@sentry/utils' ;
3
- import { DEFAULT_BROWSER_FLUSH_INTERVAL , NAME_AND_TAG_KEY_NORMALIZATION_REGEX , SET_METRIC_TYPE } from './constants' ;
3
+ import { DEFAULT_BROWSER_FLUSH_INTERVAL , SET_METRIC_TYPE } from './constants' ;
4
4
import { METRIC_MAP } from './instance' ;
5
5
import { updateMetricSummaryOnActiveSpan } from './metric-summary' ;
6
6
import type { MetricBucket , MetricType } from './types' ;
7
- import { getBucketKey , sanitizeTags } from './utils' ;
7
+ import { getBucketKey , sanitizeMetricKey , sanitizeTags , sanitizeUnit } from './utils' ;
8
8
9
9
/**
10
10
* A simple metrics aggregator that aggregates metrics in memory and flushes them periodically.
@@ -31,13 +31,14 @@ export class BrowserMetricsAggregator implements MetricsAggregator {
31
31
metricType : MetricType ,
32
32
unsanitizedName : string ,
33
33
value : number | string ,
34
- unit : MeasurementUnit | undefined = 'none' ,
34
+ unsanitizedUnit : MeasurementUnit | undefined = 'none' ,
35
35
unsanitizedTags : Record < string , Primitive > | undefined = { } ,
36
36
maybeFloatTimestamp : number | undefined = timestampInSeconds ( ) ,
37
37
) : void {
38
38
const timestamp = Math . floor ( maybeFloatTimestamp ) ;
39
- const name = unsanitizedName . replace ( NAME_AND_TAG_KEY_NORMALIZATION_REGEX , '_' ) ;
39
+ const name = sanitizeMetricKey ( unsanitizedName ) ;
40
40
const tags = sanitizeTags ( unsanitizedTags ) ;
41
+ const unit = sanitizeUnit ( unsanitizedUnit as string ) ;
41
42
42
43
const bucketKey = getBucketKey ( metricType , name , unit , tags ) ;
43
44
@@ -77,11 +78,13 @@ export class BrowserMetricsAggregator implements MetricsAggregator {
77
78
if ( this . _buckets . size === 0 ) {
78
79
return ;
79
80
}
81
+
80
82
if ( this . _client . captureAggregateMetrics ) {
81
83
// TODO(@anonrig): Use Object.values() when we support ES6+
82
84
const metricBuckets = Array . from ( this . _buckets ) . map ( ( [ , bucketItem ] ) => bucketItem ) ;
83
85
this . _client . captureAggregateMetrics ( metricBuckets ) ;
84
86
}
87
+
85
88
this . _buckets . clear ( ) ;
86
89
}
87
90
0 commit comments