Skip to content

Commit 38bd3f2

Browse files
Fixes latest route name and source not updating correctly
1 parent 74b0f11 commit 38bd3f2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
188188
startTrackingInteractions();
189189
}
190190

191-
let latestRouteName: string | undefined;
192-
let latestRouteSource: TransactionSource | undefined;
191+
const latestRoute: { name: string | undefined; source: TransactionSource | undefined } = {
192+
name: undefined,
193+
source: undefined,
194+
};
193195

194196
/** Create routing idle transaction. */
195197
function _createRouteTransaction(context: TransactionContext): Transaction | undefined {
@@ -235,8 +237,8 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
235237
: // eslint-disable-next-line deprecation/deprecation
236238
finalContext.metadata;
237239

238-
latestRouteName = finalContext.name;
239-
latestRouteSource = getSource(finalContext);
240+
latestRoute.name = finalContext.name;
241+
latestRoute.source = getSource(finalContext);
240242

241243
if (finalContext.sampled === false) {
242244
DEBUG_BUILD && logger.log(`[Tracing] Will not send ${finalContext.op} transaction because of beforeNavigate.`);
@@ -384,7 +386,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
384386
}
385387

386388
if (_experiments.enableInteractions) {
387-
registerInteractionListener(options, latestRouteName, latestRouteSource);
389+
registerInteractionListener(options, latestRoute);
388390
}
389391

390392
instrumentOutgoingRequests({
@@ -446,8 +448,7 @@ export function getMetaContent(metaName: string): string | undefined {
446448
/** Start listener for interaction transactions */
447449
function registerInteractionListener(
448450
options: BrowserTracingOptions,
449-
latestRouteName: string | undefined,
450-
latestRouteSource: TransactionSource | undefined,
451+
latestRoute: { name: string | undefined; source: TransactionSource | undefined },
451452
): void {
452453
let inflightInteractionTransaction: IdleTransaction | undefined;
453454
const registerInteractionTransaction = (): void => {
@@ -470,19 +471,19 @@ function registerInteractionListener(
470471
inflightInteractionTransaction = undefined;
471472
}
472473

473-
if (!latestRouteName) {
474+
if (!latestRoute.name) {
474475
DEBUG_BUILD && logger.warn(`[Tracing] Did not create ${op} transaction because _latestRouteName is missing.`);
475476
return undefined;
476477
}
477478

478479
const { location } = WINDOW;
479480

480481
const context: TransactionContext = {
481-
name: latestRouteName,
482+
name: latestRoute.name,
482483
op,
483484
trimEnd: true,
484485
data: {
485-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRouteSource || 'url',
486+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRoute.source || 'url',
486487
},
487488
};
488489

0 commit comments

Comments
 (0)