@@ -6,8 +6,9 @@ import type {
66 Primitive ,
77} from '@sentry/types' ;
88import { 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' ;
1010import { METRIC_MAP } from './instance' ;
11+ import { updateMetricSummaryOnActiveSpan } from './metric-summary' ;
1112import type { MetricBucket , MetricType } from './types' ;
1213import { getBucketKey , sanitizeTags } from './utils' ;
1314
@@ -62,7 +63,11 @@ export class MetricsAggregator implements MetricsAggregatorBase {
6263 const tags = sanitizeTags ( unsanitizedTags ) ;
6364
6465 const bucketKey = getBucketKey ( metricType , name , unit , tags ) ;
66+
6567 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+
6671 if ( bucketItem ) {
6772 bucketItem . metric . add ( value ) ;
6873 // TODO(abhi): Do we need this check?
@@ -82,6 +87,10 @@ export class MetricsAggregator implements MetricsAggregatorBase {
8287 this . _buckets . set ( bucketKey , bucketItem ) ;
8388 }
8489
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+
8594 // We need to keep track of the total weight of the buckets so that we can
8695 // flush them when we exceed the max weight.
8796 this . _bucketsTotalWeight += bucketItem . metric . weight ;
0 commit comments