@@ -2,7 +2,6 @@ import type { MeasurementUnit, Span } from '@sentry/types';
22import type { MetricSummary } from '@sentry/types' ;
33import type { Primitive } from '@sentry/types' ;
44import { dropUndefinedKeys } from '@sentry/utils' ;
5- import { getActiveSpan } from '../tracing/utils' ;
65import type { MetricType } from './types' ;
76
87/**
@@ -40,52 +39,50 @@ export function getMetricSummaryJsonForSpan(span: Span): Record<string, Array<Me
4039}
4140
4241/**
43- * Updates the metric summary on the currently active span
42+ * Updates the metric summary on a span.
4443 */
45- export function updateMetricSummaryOnActiveSpan (
44+ export function updateMetricSummaryOnSpan (
45+ span : Span ,
4646 metricType : MetricType ,
4747 sanitizedName : string ,
4848 value : number ,
4949 unit : MeasurementUnit ,
5050 tags : Record < string , Primitive > ,
5151 bucketKey : string ,
5252) : void {
53- const span = getActiveSpan ( ) ;
54- if ( span ) {
55- const storage = getMetricStorageForSpan ( span ) || new Map < string , [ string , MetricSummary ] > ( ) ;
53+ const storage = getMetricStorageForSpan ( span ) || new Map < string , [ string , MetricSummary ] > ( ) ;
5654
57- const exportKey = `${ metricType } :${ sanitizedName } @${ unit } ` ;
58- const bucketItem = storage . get ( bucketKey ) ;
55+ const exportKey = `${ metricType } :${ sanitizedName } @${ unit } ` ;
56+ const bucketItem = storage . get ( bucketKey ) ;
5957
60- if ( bucketItem ) {
61- const [ , summary ] = bucketItem ;
62- storage . set ( bucketKey , [
63- exportKey ,
64- {
65- min : Math . min ( summary . min , value ) ,
66- max : Math . max ( summary . max , value ) ,
67- count : ( summary . count += 1 ) ,
68- sum : ( summary . sum += value ) ,
69- tags : summary . tags ,
70- } ,
71- ] ) ;
72- } else {
73- storage . set ( bucketKey , [
74- exportKey ,
75- {
76- min : value ,
77- max : value ,
78- count : 1 ,
79- sum : value ,
80- tags,
81- } ,
82- ] ) ;
83- }
84-
85- if ( ! SPAN_METRIC_SUMMARY ) {
86- SPAN_METRIC_SUMMARY = new WeakMap ( ) ;
87- }
58+ if ( bucketItem ) {
59+ const [ , summary ] = bucketItem ;
60+ storage . set ( bucketKey , [
61+ exportKey ,
62+ {
63+ min : Math . min ( summary . min , value ) ,
64+ max : Math . max ( summary . max , value ) ,
65+ count : ( summary . count += 1 ) ,
66+ sum : ( summary . sum += value ) ,
67+ tags : summary . tags ,
68+ } ,
69+ ] ) ;
70+ } else {
71+ storage . set ( bucketKey , [
72+ exportKey ,
73+ {
74+ min : value ,
75+ max : value ,
76+ count : 1 ,
77+ sum : value ,
78+ tags,
79+ } ,
80+ ] ) ;
81+ }
8882
89- SPAN_METRIC_SUMMARY . set ( span , storage ) ;
83+ if ( ! SPAN_METRIC_SUMMARY ) {
84+ SPAN_METRIC_SUMMARY = new WeakMap ( ) ;
9085 }
86+
87+ SPAN_METRIC_SUMMARY . set ( span , storage ) ;
9188}
0 commit comments