Skip to content

Commit

Permalink
Fixes latest route name and source not updating correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardgou-sentry committed Feb 16, 2024
1 parent 74b0f11 commit 38bd3f2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/tracing-internal/src/browser/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
startTrackingInteractions();
}

let latestRouteName: string | undefined;
let latestRouteSource: TransactionSource | undefined;
const latestRoute: { name: string | undefined; source: TransactionSource | undefined } = {
name: undefined,
source: undefined,
};

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

latestRouteName = finalContext.name;
latestRouteSource = getSource(finalContext);
latestRoute.name = finalContext.name;
latestRoute.source = getSource(finalContext);

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

if (_experiments.enableInteractions) {
registerInteractionListener(options, latestRouteName, latestRouteSource);
registerInteractionListener(options, latestRoute);
}

instrumentOutgoingRequests({
Expand Down Expand Up @@ -446,8 +448,7 @@ export function getMetaContent(metaName: string): string | undefined {
/** Start listener for interaction transactions */
function registerInteractionListener(
options: BrowserTracingOptions,
latestRouteName: string | undefined,
latestRouteSource: TransactionSource | undefined,
latestRoute: { name: string | undefined; source: TransactionSource | undefined },
): void {
let inflightInteractionTransaction: IdleTransaction | undefined;
const registerInteractionTransaction = (): void => {
Expand All @@ -470,19 +471,19 @@ function registerInteractionListener(
inflightInteractionTransaction = undefined;
}

if (!latestRouteName) {
if (!latestRoute.name) {
DEBUG_BUILD && logger.warn(`[Tracing] Did not create ${op} transaction because _latestRouteName is missing.`);
return undefined;
}

const { location } = WINDOW;

const context: TransactionContext = {
name: latestRouteName,
name: latestRoute.name,
op,
trimEnd: true,
data: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRouteSource || 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRoute.source || 'url',
},
};

Expand Down

0 comments on commit 38bd3f2

Please sign in to comment.