@@ -2,7 +2,7 @@ import type { Client, DurationUnit, MetricData, MetricsAggregator as MetricsAggr
2
2
import { getGlobalSingleton , logger , timestampInSeconds } from '@sentry/utils' ;
3
3
import { getClient } from '../currentScopes' ;
4
4
import { DEBUG_BUILD } from '../debug-build' ;
5
- import { startInactiveSpan } from '../tracing' ;
5
+ import { startSpanManual } from '../tracing' ;
6
6
import { handleCallbackErrors } from '../utils/handleCallbackErrors' ;
7
7
import { getActiveSpan , getRootSpan , spanToJSON } from '../utils/spanUtils' ;
8
8
import { COUNTER_METRIC_TYPE , DISTRIBUTION_METRIC_TYPE , GAUGE_METRIC_TYPE , SET_METRIC_TYPE } from './constants' ;
@@ -111,23 +111,27 @@ function timing<T = void>(
111
111
// callback form
112
112
if ( typeof value === 'function' ) {
113
113
const startTime = timestampInSeconds ( ) ;
114
- const span = startInactiveSpan ( {
115
- op : 'metrics.timing' ,
116
- name,
117
- startTime,
118
- onlyIfParent : true ,
119
- } ) ;
120
-
121
- return handleCallbackErrors (
122
- ( ) => value ( ) ,
123
- ( ) => {
124
- // no special error handling necessary
114
+
115
+ return startSpanManual (
116
+ {
117
+ op : 'metrics.timing' ,
118
+ name,
119
+ startTime,
120
+ onlyIfParent : true ,
125
121
} ,
126
- ( ) => {
127
- const endTime = timestampInSeconds ( ) ;
128
- const timeDiff = endTime - startTime ;
129
- distribution ( aggregator , name , timeDiff , { ...data , unit : 'second' } ) ;
130
- span . end ( endTime ) ;
122
+ span => {
123
+ return handleCallbackErrors (
124
+ ( ) => value ( ) ,
125
+ ( ) => {
126
+ // no special error handling necessary
127
+ } ,
128
+ ( ) => {
129
+ const endTime = timestampInSeconds ( ) ;
130
+ const timeDiff = endTime - startTime ;
131
+ distribution ( aggregator , name , timeDiff , { ...data , unit : 'second' } ) ;
132
+ span . end ( endTime ) ;
133
+ } ,
134
+ ) ;
131
135
} ,
132
136
) ;
133
137
}
0 commit comments