Skip to content

Commit

Permalink
fix(tracing): Fixes latest route name and source not updating correct…
Browse files Browse the repository at this point in the history
…ly (getsentry#11533)

Forward port of
getsentry#10702
  • Loading branch information
mydea authored and cadesalaberry committed Apr 19, 2024
1 parent 2ab66ba commit 2842911
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/browser-utils/src/browser/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,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 _createRouteSpan(client: Client, startSpanOptions: StartSpanOptions): Span {
Expand All @@ -190,8 +192,8 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
finalStartSpanOptions.attributes = attributes;
}

latestRouteName = finalStartSpanOptions.name;
latestRouteSource = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
latestRoute.name = finalStartSpanOptions.name;
latestRoute.source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];

const idleSpan = startIdleSpan(finalStartSpanOptions, {
idleTimeout,
Expand Down Expand Up @@ -333,7 +335,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
}

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

instrumentOutgoingRequests({
Expand Down Expand Up @@ -404,8 +406,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 inflightInteractionSpan: Span | undefined;
const registerInteractionTransaction = (): void => {
Expand All @@ -429,17 +430,17 @@ function registerInteractionListener(
inflightInteractionSpan = undefined;
}

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

inflightInteractionSpan = startIdleSpan(
{
name: latestRouteName,
name: latestRoute.name,
op,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRouteSource || 'url',
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: latestRoute.source || 'url',
},
},
{
Expand Down

0 comments on commit 2842911

Please sign in to comment.