|
1 | 1 | /* eslint-disable max-lines */ |
| 2 | +import { getCurrentHub } from '@sentry/core'; |
2 | 3 | import type { DynamicSamplingContext, Span } from '@sentry/types'; |
3 | 4 | import { |
4 | 5 | addInstrumentationHandler, |
|
8 | 9 | stringMatchesSomePattern, |
9 | 10 | } from '@sentry/utils'; |
10 | 11 |
|
11 | | -import { getActiveTransaction, hasTracingEnabled } from '../utils'; |
| 12 | +import { hasTracingEnabled } from '../utils'; |
12 | 13 |
|
13 | 14 | export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//]; |
14 | 15 |
|
@@ -186,9 +187,12 @@ export function fetchCallback( |
186 | 187 | return; |
187 | 188 | } |
188 | 189 |
|
189 | | - const activeTransaction = getActiveTransaction(); |
190 | | - if (activeTransaction) { |
191 | | - const span = activeTransaction.startChild({ |
| 190 | + const currentScope = getCurrentHub().getScope(); |
| 191 | + const currentSpan = currentScope && currentScope.getSpan(); |
| 192 | + const activeTransaction = currentSpan && currentSpan.transaction; |
| 193 | + |
| 194 | + if (currentSpan && activeTransaction) { |
| 195 | + const span = currentSpan.startChild({ |
192 | 196 | data: { |
193 | 197 | ...handlerData.fetchData, |
194 | 198 | type: 'fetch', |
@@ -320,10 +324,12 @@ export function xhrCallback( |
320 | 324 | return; |
321 | 325 | } |
322 | 326 |
|
323 | | - // if not, create a new span to track it |
324 | | - const activeTransaction = getActiveTransaction(); |
325 | | - if (activeTransaction) { |
326 | | - const span = activeTransaction.startChild({ |
| 327 | + const currentScope = getCurrentHub().getScope(); |
| 328 | + const currentSpan = currentScope && currentScope.getSpan(); |
| 329 | + const activeTransaction = currentSpan && currentSpan.transaction; |
| 330 | + |
| 331 | + if (currentSpan && activeTransaction) { |
| 332 | + const span = currentSpan.startChild({ |
327 | 333 | data: { |
328 | 334 | ...xhr.data, |
329 | 335 | type: 'xhr', |
|
0 commit comments