@@ -6,8 +6,9 @@ import type {
6
6
Primitive ,
7
7
} from '@sentry/types' ;
8
8
import { timestampInSeconds } from '@sentry/utils' ;
9
- import { DEFAULT_FLUSH_INTERVAL , MAX_WEIGHT , NAME_AND_TAG_KEY_NORMALIZATION_REGEX } from './constants' ;
9
+ import { DEFAULT_FLUSH_INTERVAL , MAX_WEIGHT , NAME_AND_TAG_KEY_NORMALIZATION_REGEX , SET_METRIC_TYPE } from './constants' ;
10
10
import { METRIC_MAP } from './instance' ;
11
+ import { updateMetricSummaryOnActiveSpan } from './metric-summary' ;
11
12
import type { MetricBucket , MetricType } from './types' ;
12
13
import { getBucketKey , sanitizeTags } from './utils' ;
13
14
@@ -62,7 +63,11 @@ export class MetricsAggregator implements MetricsAggregatorBase {
62
63
const tags = sanitizeTags ( unsanitizedTags ) ;
63
64
64
65
const bucketKey = getBucketKey ( metricType , name , unit , tags ) ;
66
+
65
67
let bucketItem = this . _buckets . get ( bucketKey ) ;
68
+ // If this is a set metric, we need to calculate the delta from the previous weight.
69
+ const previousWeight = bucketItem && metricType === SET_METRIC_TYPE ? bucketItem . metric . weight : 0 ;
70
+
66
71
if ( bucketItem ) {
67
72
bucketItem . metric . add ( value ) ;
68
73
// TODO(abhi): Do we need this check?
@@ -82,6 +87,10 @@ export class MetricsAggregator implements MetricsAggregatorBase {
82
87
this . _buckets . set ( bucketKey , bucketItem ) ;
83
88
}
84
89
90
+ // If value is a string, it's a set metric so calculate the delta from the previous weight.
91
+ const val = typeof value === 'string' ? bucketItem . metric . weight - previousWeight : value ;
92
+ updateMetricSummaryOnActiveSpan ( metricType , name , val , unit , unsanitizedTags , bucketKey ) ;
93
+
85
94
// We need to keep track of the total weight of the buckets so that we can
86
95
// flush them when we exceed the max weight.
87
96
this . _bucketsTotalWeight += bucketItem . metric . weight ;
0 commit comments