Skip to content

Commit d51e787

Browse files
committed
make span active
1 parent 3ca7f7d commit d51e787

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

packages/core/src/metrics/exports.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Client, DurationUnit, MetricData, MetricsAggregator as MetricsAggr
22
import { getGlobalSingleton, logger, timestampInSeconds } from '@sentry/utils';
33
import { getClient } from '../currentScopes';
44
import { DEBUG_BUILD } from '../debug-build';
5-
import { startInactiveSpan } from '../tracing';
5+
import { startSpanManual } from '../tracing';
66
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
77
import { getActiveSpan, getRootSpan, spanToJSON } from '../utils/spanUtils';
88
import { COUNTER_METRIC_TYPE, DISTRIBUTION_METRIC_TYPE, GAUGE_METRIC_TYPE, SET_METRIC_TYPE } from './constants';
@@ -111,23 +111,27 @@ function timing<T = void>(
111111
// callback form
112112
if (typeof value === 'function') {
113113
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,
125121
},
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+
);
131135
},
132136
);
133137
}

0 commit comments

Comments
 (0)