Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/tracing/src/browser/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable max-lines */
import { getCurrentHub } from '@sentry/core';
import type { DynamicSamplingContext, Span } from '@sentry/types';
import {
addInstrumentationHandler,
Expand All @@ -8,7 +9,7 @@ import {
stringMatchesSomePattern,
} from '@sentry/utils';

import { getActiveTransaction, hasTracingEnabled } from '../utils';
import { hasTracingEnabled } from '../utils';

export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//];

Expand Down Expand Up @@ -186,9 +187,12 @@ export function fetchCallback(
return;
}

const activeTransaction = getActiveTransaction();
if (activeTransaction) {
const span = activeTransaction.startChild({
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

if (currentSpan && activeTransaction) {
const span = currentSpan.startChild({
data: {
...handlerData.fetchData,
type: 'fetch',
Expand Down Expand Up @@ -320,10 +324,12 @@ export function xhrCallback(
return;
}

// if not, create a new span to track it
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
const span = activeTransaction.startChild({
const currentScope = getCurrentHub().getScope();
const currentSpan = currentScope && currentScope.getSpan();
const activeTransaction = currentSpan && currentSpan.transaction;

if (currentSpan && activeTransaction) {
const span = currentSpan.startChild({
data: {
...xhr.data,
type: 'xhr',
Expand Down