Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes latest route name and source not updating correctly #10702

Merged
merged 2 commits into from
Feb 22, 2024
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
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
Loading