@sentry/react-router 10.64.0 → 10.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ const core = require('@sentry/core');
5
5
  const debugBuild = require('../common/debug-build.js');
6
6
  const utils = require('../common/utils.js');
7
7
  const utils$1 = require('./utils.js');
8
+ const attributes = require('@sentry/conventions/attributes');
8
9
 
9
10
  const WINDOW = core.GLOBAL_OBJ;
10
11
  let currentNumericNavigationSpan;
@@ -31,20 +32,24 @@ function createSentryClientInstrumentation(options = {}) {
31
32
  const pathname = WINDOW.location?.pathname || "/";
32
33
  if (currentNumericNavigationSpan) {
33
34
  if (currentNumericNavigationSpan.isRecording()) {
34
- currentNumericNavigationSpan.updateName(pathname);
35
+ utils$1.updateNavigationSpanUrlFromLocation(currentNumericNavigationSpan);
35
36
  }
36
37
  currentNumericNavigationSpan = void 0;
37
38
  return;
38
39
  }
39
- browser.startBrowserTracingNavigationSpan(client, {
40
- name: pathname,
41
- attributes: {
42
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
43
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
44
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
45
- "navigation.type": "browser.popstate"
46
- }
47
- });
40
+ browser.startBrowserTracingNavigationSpan(
41
+ client,
42
+ {
43
+ name: pathname,
44
+ attributes: {
45
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
46
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
47
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
48
+ "navigation.type": "browser.popstate"
49
+ }
50
+ },
51
+ { url: browser.getAbsoluteUrl(pathname) }
52
+ );
48
53
  });
49
54
  debugBuild.DEBUG_BUILD && core.debug.log("React Router popstate listener registered for browser back/forward navigation.");
50
55
  }
@@ -66,21 +71,25 @@ function createSentryClientInstrumentation(options = {}) {
66
71
  if (client2) {
67
72
  const navigationType = info.to < 0 ? "router.back" : "router.forward";
68
73
  const currentPathname = WINDOW.location?.pathname || info.currentUrl;
69
- navigationSpan2 = browser.startBrowserTracingNavigationSpan(client2, {
70
- name: currentPathname,
71
- attributes: {
72
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
73
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
74
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
75
- "navigation.type": navigationType
76
- }
77
- });
74
+ navigationSpan2 = browser.startBrowserTracingNavigationSpan(
75
+ client2,
76
+ {
77
+ name: currentPathname,
78
+ attributes: {
79
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
80
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
81
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
82
+ "navigation.type": navigationType
83
+ }
84
+ },
85
+ { url: browser.getAbsoluteUrl(currentPathname) }
86
+ );
78
87
  currentNumericNavigationSpan = navigationSpan2;
79
88
  }
80
89
  try {
81
90
  const result2 = await callNavigate();
82
91
  if (navigationSpan2 && WINDOW.location) {
83
- navigationSpan2.updateName(WINDOW.location.pathname);
92
+ utils$1.finalizeNavigationSpanFromHydratedRouter(navigationSpan2);
84
93
  }
85
94
  if (result2.status === "error" && result2.error instanceof Error) {
86
95
  if (navigationSpan2) {
@@ -99,15 +108,19 @@ function createSentryClientInstrumentation(options = {}) {
99
108
  const toPath = utils$1.resolveNavigateArg(info.to);
100
109
  let navigationSpan;
101
110
  if (client) {
102
- navigationSpan = browser.startBrowserTracingNavigationSpan(client, {
103
- name: toPath,
104
- attributes: {
105
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
106
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
107
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
108
- "navigation.type": "router.navigate"
109
- }
110
- });
111
+ navigationSpan = browser.startBrowserTracingNavigationSpan(
112
+ client,
113
+ {
114
+ name: toPath,
115
+ attributes: {
116
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
117
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
118
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
119
+ "navigation.type": "router.navigate"
120
+ }
121
+ },
122
+ { url: utils$1.resolveNavigateAbsoluteUrl(info.to, info.currentUrl) }
123
+ );
111
124
  }
112
125
  const result = await callNavigate();
113
126
  if (result.status === "error" && result.error instanceof Error) {
@@ -261,7 +274,7 @@ function updateRootSpanRoute(routeName, hasPattern) {
261
274
  return;
262
275
  }
263
276
  core.updateSpanName(rootSpan, routeName);
264
- rootSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route");
277
+ rootSpan.setAttributes({ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [attributes.URL_TEMPLATE]: routeName });
265
278
  }
266
279
  function isClientInstrumentationApiUsed() {
267
280
  return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];
@@ -1 +1 @@
1
- {"version":3,"file":"createClientInstrumentation.js","sources":["../../../src/client/createClientInstrumentation.ts"],"sourcesContent":["import { startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { ClientInstrumentation, InstrumentableRoute, InstrumentableRouter } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport { resolveNavigateArg } from './utils';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\n// Tracks active numeric navigation span to prevent duplicate spans when popstate fires\nlet currentNumericNavigationSpan: Span | undefined;\n\n// Per-request middleware counters, keyed by Request\nconst middlewareCountersMap = new WeakMap<object, Record<string, number>>();\n\nconst SENTRY_CLIENT_INSTRUMENTATION_FLAG = '__sentryReactRouterClientInstrumentationUsed';\n// Intentionally never reset - once set, instrumentation API handles all navigations for the session.\nconst SENTRY_NAVIGATE_HOOK_INVOKED_FLAG = '__sentryReactRouterNavigateHookInvoked';\nconst SENTRY_POPSTATE_LISTENER_ADDED_FLAG = '__sentryReactRouterPopstateListenerAdded';\n\ntype GlobalObjWithFlags = typeof GLOBAL_OBJ & {\n [SENTRY_CLIENT_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_NAVIGATE_HOOK_INVOKED_FLAG]?: boolean;\n [SENTRY_POPSTATE_LISTENER_ADDED_FLAG]?: boolean;\n};\n\nconst GLOBAL_WITH_FLAGS = GLOBAL_OBJ as GlobalObjWithFlags;\n\n/**\n * Options for creating Sentry client instrumentation.\n */\nexport interface CreateSentryClientInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * Set to `false` to avoid duplicates if using custom error handlers.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry client instrumentation for React Router's instrumentation API.\n */\nexport function createSentryClientInstrumentation(\n options: CreateSentryClientInstrumentationOptions = {},\n): ClientInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router client instrumentation API created.');\n\n return {\n router(router: InstrumentableRouter) {\n // Set the flag when React Router actually invokes our instrumentation.\n // This ensures the flag is only set in Library Mode (where hooks run),\n // not in Framework Mode (where hooks are never called).\n // See: https://github.com/remix-run/react-router/discussions/13749\n GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG] = true;\n DEBUG_BUILD && debug.log('React Router client instrumentation API router hook registered.');\n\n // Add popstate listener for browser back/forward navigation (persists for session, one listener only)\n if (!GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] && WINDOW.addEventListener) {\n GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] = true;\n\n WINDOW.addEventListener('popstate', () => {\n const client = getClient();\n if (!client) {\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n const pathname = WINDOW.location?.pathname || '/';\n\n // If there's an active numeric navigation span, update it instead of creating a duplicate\n if (currentNumericNavigationSpan) {\n if (currentNumericNavigationSpan.isRecording()) {\n currentNumericNavigationSpan.updateName(pathname);\n }\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n // Only create a new span for actual browser back/forward button clicks\n startBrowserTracingNavigationSpan(client, {\n name: pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'browser.popstate',\n },\n });\n });\n\n DEBUG_BUILD && debug.log('React Router popstate listener registered for browser back/forward navigation.');\n }\n\n router.instrument({\n async navigate(callNavigate, info) {\n // navigate(0) triggers a page reload - skip span creation, but still capture errors\n // (navigation can be rejected before reload, e.g., by a navigation guard)\n if (info.to === 0) {\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': info.currentUrl,\n });\n }\n return;\n }\n\n GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG] = true;\n\n // Handle numeric navigations (navigate(-1), navigate(1), etc.)\n if (typeof info.to === 'number') {\n const client = getClient();\n let navigationSpan;\n\n if (client) {\n const navigationType = info.to < 0 ? 'router.back' : 'router.forward';\n const currentPathname = WINDOW.location?.pathname || info.currentUrl;\n\n navigationSpan = startBrowserTracingNavigationSpan(client, {\n name: currentPathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': navigationType,\n },\n });\n\n // Store ref so popstate listener can update it instead of creating a duplicate\n currentNumericNavigationSpan = navigationSpan;\n }\n\n try {\n const result = await callNavigate();\n\n if (navigationSpan && WINDOW.location) {\n navigationSpan.updateName(WINDOW.location.pathname);\n }\n\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': WINDOW.location?.pathname || info.currentUrl,\n });\n }\n } finally {\n currentNumericNavigationSpan = undefined;\n }\n return;\n }\n\n // Handle string/object navigations (e.g., navigate('/about') or navigate({ pathname: '/about' }))\n const client = getClient();\n const toPath = resolveNavigateArg(info.to);\n let navigationSpan;\n\n if (client) {\n navigationSpan = startBrowserTracingNavigationSpan(client, {\n name: toPath,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'router.navigate',\n },\n });\n }\n\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': toPath,\n });\n }\n return;\n },\n\n async fetch(callFetch, info) {\n await startSpan(\n {\n name: `Fetcher ${info.fetcherKey}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.fetcher',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callFetch();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.fetcher', {\n 'http.url': info.href,\n });\n }\n },\n );\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n // Parameterize the active navigation root span. (Route hooks don't fire on initial\n // pageload, so this only affects navigations.)\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_loader', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_action', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const routePattern = normalizeRoutePath(getPattern(info)) || urlPath;\n\n let counters = middlewareCountersMap.get(info.request);\n if (!counters) {\n counters = {};\n middlewareCountersMap.set(info.request, counters);\n }\n\n const middlewareIndex = counters[routeId] ?? 0;\n counters[routeId] = middlewareIndex + 1;\n\n await startSpan(\n {\n name: `middleware ${routeId}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n 'http.route': routePattern,\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_middleware', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\n/**\n * Updates the active navigation/pageload root span name with the parameterized route, so the\n * transaction reflects the parameterized route pattern (e.g. `/users/:id`).\n */\nfunction updateRootSpanRoute(routeName: string, hasPattern: boolean): void {\n if (!hasPattern) {\n return;\n }\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n if (!rootSpan) {\n return;\n }\n\n const { op } = spanToJSON(rootSpan);\n if (op !== 'navigation' && op !== 'pageload') {\n return;\n }\n\n updateSpanName(rootSpan, routeName);\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n}\n\n/**\n * Check if React Router's instrumentation API is being used on the client.\n */\nexport function isClientInstrumentationApiUsed(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Check if React Router's instrumentation API's navigate hook was invoked.\n */\nexport function isNavigateHookInvoked(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG];\n}\n"],"names":["GLOBAL_OBJ","DEBUG_BUILD","debug","getClient","startBrowserTracingNavigationSpan","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","result","captureInstrumentationError","client","navigationSpan","SPAN_STATUS_ERROR","resolveNavigateArg","startSpan","getPathFromRequest","normalizeRoutePath","getPattern","getActiveSpan","getRootSpan","spanToJSON","updateSpanName"],"mappings":";;;;;;;;AAqBA,MAAM,MAAA,GAASA,eAAA;AAGf,IAAI,4BAAA;AAGJ,MAAM,qBAAA,uBAA4B,OAAA,EAAwC;AAE1E,MAAM,kCAAA,GAAqC,8CAAA;AAE3C,MAAM,iCAAA,GAAoC,wCAAA;AAC1C,MAAM,mCAAA,GAAsC,0CAAA;AAQ5C,MAAM,iBAAA,GAAoBA,eAAA;AAiBnB,SAAS,iCAAA,CACd,OAAA,GAAoD,EAAC,EAC9B;AACvB,EAAA,MAAM,EAAE,aAAA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,UAAA,IAAcC,gBAAA,CAAY,UAAU,CAAA;AACrD,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,EAAE,EAAA,EAAG,GAAIC,eAAA,CAAW,QAAQ,CAAA;AAClC,EAAA,IAAI,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,EAAY;AAC5C,IAAA;AAAA,EACF;AAEA,EAAAC,mBAAA,CAAe,UAAU,SAAS,CAAA;AAClC,EAAA,QAAA,CAAS,YAAA,CAAahB,uCAAkC,OAAO,CAAA;AACjE;AAKO,SAAS,8BAAA,GAA0C;AACxD,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,kCAAkC,CAAA;AAC/D;AAKO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,iCAAiC,CAAA;AAC9D;;;;;;"}
1
+ {"version":3,"file":"createClientInstrumentation.js","sources":["../../../src/client/createClientInstrumentation.ts"],"sourcesContent":["// oxlint-disable max-lines\nimport { getAbsoluteUrl, startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { ClientInstrumentation, InstrumentableRoute, InstrumentableRouter } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport {\n resolveNavigateAbsoluteUrl,\n resolveNavigateArg,\n finalizeNavigationSpanFromHydratedRouter,\n updateNavigationSpanUrlFromLocation,\n} from './utils';\nimport { URL_TEMPLATE } from '@sentry/conventions/attributes';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\n// Tracks active numeric navigation span to prevent duplicate spans when popstate fires\nlet currentNumericNavigationSpan: Span | undefined;\n\n// Per-request middleware counters, keyed by Request\nconst middlewareCountersMap = new WeakMap<object, Record<string, number>>();\n\nconst SENTRY_CLIENT_INSTRUMENTATION_FLAG = '__sentryReactRouterClientInstrumentationUsed';\n// Intentionally never reset - once set, instrumentation API handles all navigations for the session.\nconst SENTRY_NAVIGATE_HOOK_INVOKED_FLAG = '__sentryReactRouterNavigateHookInvoked';\nconst SENTRY_POPSTATE_LISTENER_ADDED_FLAG = '__sentryReactRouterPopstateListenerAdded';\n\ntype GlobalObjWithFlags = typeof GLOBAL_OBJ & {\n [SENTRY_CLIENT_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_NAVIGATE_HOOK_INVOKED_FLAG]?: boolean;\n [SENTRY_POPSTATE_LISTENER_ADDED_FLAG]?: boolean;\n};\n\nconst GLOBAL_WITH_FLAGS = GLOBAL_OBJ as GlobalObjWithFlags;\n\n/**\n * Options for creating Sentry client instrumentation.\n */\nexport interface CreateSentryClientInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * Set to `false` to avoid duplicates if using custom error handlers.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry client instrumentation for React Router's instrumentation API.\n */\nexport function createSentryClientInstrumentation(\n options: CreateSentryClientInstrumentationOptions = {},\n): ClientInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router client instrumentation API created.');\n\n return {\n router(router: InstrumentableRouter) {\n // Set the flag when React Router actually invokes our instrumentation.\n // This ensures the flag is only set in Library Mode (where hooks run),\n // not in Framework Mode (where hooks are never called).\n // See: https://github.com/remix-run/react-router/discussions/13749\n GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG] = true;\n DEBUG_BUILD && debug.log('React Router client instrumentation API router hook registered.');\n\n // Add popstate listener for browser back/forward navigation (persists for session, one listener only)\n if (!GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] && WINDOW.addEventListener) {\n GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] = true;\n\n WINDOW.addEventListener('popstate', () => {\n const client = getClient();\n if (!client) {\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n const pathname = WINDOW.location?.pathname || '/';\n\n // If there's an active numeric navigation span, update it instead of creating a duplicate\n if (currentNumericNavigationSpan) {\n if (currentNumericNavigationSpan.isRecording()) {\n updateNavigationSpanUrlFromLocation(currentNumericNavigationSpan);\n }\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n // Only create a new span for actual browser back/forward button clicks\n startBrowserTracingNavigationSpan(\n client,\n {\n name: pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'browser.popstate',\n },\n },\n { url: getAbsoluteUrl(pathname) },\n );\n });\n\n DEBUG_BUILD && debug.log('React Router popstate listener registered for browser back/forward navigation.');\n }\n\n router.instrument({\n async navigate(callNavigate, info) {\n // navigate(0) triggers a page reload - skip span creation, but still capture errors\n // (navigation can be rejected before reload, e.g., by a navigation guard)\n if (info.to === 0) {\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': info.currentUrl,\n });\n }\n return;\n }\n\n GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG] = true;\n\n // Handle numeric navigations (navigate(-1), navigate(1), etc.)\n if (typeof info.to === 'number') {\n const client = getClient();\n let navigationSpan;\n\n if (client) {\n const navigationType = info.to < 0 ? 'router.back' : 'router.forward';\n const currentPathname = WINDOW.location?.pathname || info.currentUrl;\n\n navigationSpan = startBrowserTracingNavigationSpan(\n client,\n {\n name: currentPathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': navigationType,\n },\n },\n { url: getAbsoluteUrl(currentPathname) },\n );\n\n // Store ref so popstate listener can update it instead of creating a duplicate\n currentNumericNavigationSpan = navigationSpan;\n }\n\n try {\n const result = await callNavigate();\n\n if (navigationSpan && WINDOW.location) {\n finalizeNavigationSpanFromHydratedRouter(navigationSpan);\n }\n\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': WINDOW.location?.pathname || info.currentUrl,\n });\n }\n } finally {\n currentNumericNavigationSpan = undefined;\n }\n return;\n }\n\n // Handle string/object navigations (e.g., navigate('/about') or navigate({ pathname: '/about' }))\n const client = getClient();\n const toPath = resolveNavigateArg(info.to);\n let navigationSpan;\n\n if (client) {\n navigationSpan = startBrowserTracingNavigationSpan(\n client,\n {\n name: toPath,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'router.navigate',\n },\n },\n { url: resolveNavigateAbsoluteUrl(info.to, info.currentUrl) },\n );\n }\n\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': toPath,\n });\n }\n return;\n },\n\n async fetch(callFetch, info) {\n await startSpan(\n {\n name: `Fetcher ${info.fetcherKey}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.fetcher',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callFetch();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.fetcher', {\n 'http.url': info.href,\n });\n }\n },\n );\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n // Parameterize the active navigation root span. (Route hooks don't fire on initial\n // pageload, so this only affects navigations.)\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_loader', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_action', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const routePattern = normalizeRoutePath(getPattern(info)) || urlPath;\n\n let counters = middlewareCountersMap.get(info.request);\n if (!counters) {\n counters = {};\n middlewareCountersMap.set(info.request, counters);\n }\n\n const middlewareIndex = counters[routeId] ?? 0;\n counters[routeId] = middlewareIndex + 1;\n\n await startSpan(\n {\n name: `middleware ${routeId}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n 'http.route': routePattern,\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_middleware', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\n/**\n * Updates the active navigation/pageload root span name with the parameterized route, so the\n * transaction reflects the parameterized route pattern (e.g. `/users/:id`).\n */\nfunction updateRootSpanRoute(routeName: string, hasPattern: boolean): void {\n if (!hasPattern) {\n return;\n }\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n if (!rootSpan) {\n return;\n }\n\n const { op } = spanToJSON(rootSpan);\n if (op !== 'navigation' && op !== 'pageload') {\n return;\n }\n\n updateSpanName(rootSpan, routeName);\n rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: routeName });\n}\n\n/**\n * Check if React Router's instrumentation API is being used on the client.\n */\nexport function isClientInstrumentationApiUsed(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Check if React Router's instrumentation API's navigate hook was invoked.\n */\nexport function isNavigateHookInvoked(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG];\n}\n"],"names":["GLOBAL_OBJ","DEBUG_BUILD","debug","getClient","updateNavigationSpanUrlFromLocation","startBrowserTracingNavigationSpan","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","getAbsoluteUrl","result","captureInstrumentationError","client","navigationSpan","finalizeNavigationSpanFromHydratedRouter","SPAN_STATUS_ERROR","resolveNavigateArg","resolveNavigateAbsoluteUrl","startSpan","getPathFromRequest","normalizeRoutePath","getPattern","getActiveSpan","getRootSpan","spanToJSON","updateSpanName","URL_TEMPLATE"],"mappings":";;;;;;;;;AA4BA,MAAM,MAAA,GAASA,eAAA;AAGf,IAAI,4BAAA;AAGJ,MAAM,qBAAA,uBAA4B,OAAA,EAAwC;AAE1E,MAAM,kCAAA,GAAqC,8CAAA;AAE3C,MAAM,iCAAA,GAAoC,wCAAA;AAC1C,MAAM,mCAAA,GAAsC,0CAAA;AAQ5C,MAAM,iBAAA,GAAoBA,eAAA;AAiBnB,SAAS,iCAAA,CACd,O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0BAAA,EAA4B,EAAE,CAAA;AAAA,cACnF;AAAA,YACF;AAAA,WACF;AAAA,QACF;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACF;AACF;AAMA,SAAS,mBAAA,CAAoB,WAAmB,UAAA,EAA2B;AACzE,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,aAAaW,kBAAA,EAAc;AACjC,EAAA,MAAM,QAAA,GAAW,UAAA,IAAcC,gBAAA,CAAY,UAAU,CAAA;AACrD,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,EAAE,EAAA,EAAG,GAAIC,eAAA,CAAW,QAAQ,CAAA;AAClC,EAAA,IAAI,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,EAAY;AAC5C,IAAA;AAAA,EACF;AAEA,EAAAC,mBAAA,CAAe,UAAU,SAAS,CAAA;AAClC,EAAA,QAAA,CAAS,aAAA,CAAc,EAAE,CAACnB,qCAAgC,GAAG,SAAS,CAACoB,uBAAY,GAAG,SAAA,EAAW,CAAA;AACnG;AAKO,SAAS,8BAAA,GAA0C;AACxD,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,kCAAkC,CAAA;AAC/D;AAKO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,iCAAiC,CAAA;AAC9D;;;;;;"}
@@ -5,8 +5,10 @@ const core = require('@sentry/core');
5
5
  const debugBuild = require('../common/debug-build.js');
6
6
  const createClientInstrumentation = require('./createClientInstrumentation.js');
7
7
  const utils = require('./utils.js');
8
+ const attributes = require('@sentry/conventions/attributes');
8
9
 
9
10
  const GLOBAL_OBJ_WITH_DATA_ROUTER = core.GLOBAL_OBJ;
11
+ const WINDOW = core.GLOBAL_OBJ;
10
12
  const MAX_RETRIES = 40;
11
13
  function instrumentHydratedRouter() {
12
14
  function trySubscribe() {
@@ -15,13 +17,14 @@ function instrumentHydratedRouter() {
15
17
  const pageloadSpan = getActiveRootSpan();
16
18
  if (pageloadSpan) {
17
19
  const pageloadName = core.spanToJSON(pageloadSpan).description;
18
- const parameterizePageloadRoute = getParameterizedRoute(router.state);
20
+ const parameterizePageloadRoute = utils.getParameterizedRoute(router.state);
19
21
  if (pageloadName && // this event is for the currently active pageload
20
- normalizePathname(router.state.location.pathname) === normalizePathname(pageloadName)) {
22
+ utils.normalizePathname(router.state.location.pathname) === utils.normalizePathname(pageloadName)) {
21
23
  pageloadSpan.updateName(parameterizePageloadRoute);
22
24
  pageloadSpan.setAttributes({
23
25
  [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route",
24
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react_router"
26
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react_router",
27
+ [attributes.URL_TEMPLATE]: parameterizePageloadRoute
25
28
  });
26
29
  }
27
30
  }
@@ -29,7 +32,35 @@ function instrumentHydratedRouter() {
29
32
  const originalNav = router.navigate.bind(router);
30
33
  router.navigate = function sentryPatchedNavigate(...args) {
31
34
  if (!createClientInstrumentation.isClientInstrumentationApiUsed()) {
32
- maybeCreateNavigationTransaction(utils.resolveNavigateArg(args[0]) || "<unknown route>", "url");
35
+ const target = args[0];
36
+ if (typeof target === "number") {
37
+ if (target !== 0) {
38
+ const currentPathname = WINDOW.location?.pathname || "/";
39
+ const navigationSpan = maybeCreateNavigationTransaction(
40
+ currentPathname,
41
+ browser.getAbsoluteUrl(currentPathname),
42
+ "url"
43
+ );
44
+ const result = originalNav(...args);
45
+ if (navigationSpan) {
46
+ if (core.isThenable(result)) {
47
+ result.then(
48
+ () => utils.finalizeNavigationSpanFromRouterState(navigationSpan, router.state),
49
+ () => utils.finalizeNavigationSpanFromRouterState(navigationSpan, router.state)
50
+ );
51
+ } else {
52
+ utils.finalizeNavigationSpanFromRouterState(navigationSpan, router.state);
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ } else {
58
+ maybeCreateNavigationTransaction(
59
+ utils.resolveNavigateArg(target) || "<unknown route>",
60
+ utils.resolveNavigateAbsoluteUrl(target),
61
+ "url"
62
+ );
63
+ }
33
64
  }
34
65
  return originalNav(...args);
35
66
  };
@@ -44,12 +75,14 @@ function instrumentHydratedRouter() {
44
75
  return;
45
76
  }
46
77
  const rootSpanName = rootSpanJson.description;
47
- const parameterizedRoute = getParameterizedRoute(newState);
78
+ const parameterizedRoute = utils.getParameterizedRoute(newState);
79
+ const spanPathname = rootSpanJson.data?.[attributes.URL_PATH];
80
+ const destinationPathname = utils.normalizePathname(newState.location.pathname);
48
81
  if (rootSpanName && newState.navigation.state === "idle" && // navigation has completed
49
82
  // this event is for the currently active root span
50
- normalizePathname(newState.location.pathname) === normalizePathname(rootSpanName)) {
83
+ (destinationPathname === utils.normalizePathname(rootSpanName) || spanPathname && destinationPathname === utils.normalizePathname(spanPathname))) {
51
84
  rootSpan.updateName(parameterizedRoute);
52
- rootSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route");
85
+ rootSpan.setAttributes({ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [attributes.URL_TEMPLATE]: parameterizedRoute });
53
86
  }
54
87
  });
55
88
  return true;
@@ -69,19 +102,24 @@ function instrumentHydratedRouter() {
69
102
  }, 50);
70
103
  }
71
104
  }
72
- function maybeCreateNavigationTransaction(name, source) {
105
+ function maybeCreateNavigationTransaction(name, url, source) {
73
106
  const client = core.getClient();
74
107
  if (!client) {
75
108
  return void 0;
76
109
  }
77
- return browser.startBrowserTracingNavigationSpan(client, {
78
- name,
79
- attributes: {
80
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
81
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
82
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router"
83
- }
84
- });
110
+ return browser.startBrowserTracingNavigationSpan(
111
+ client,
112
+ {
113
+ name,
114
+ attributes: {
115
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
116
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
117
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router",
118
+ ...{}
119
+ }
120
+ },
121
+ { url }
122
+ );
85
123
  }
86
124
  function getActiveRootSpan() {
87
125
  const activeSpan = core.getActiveSpan();
@@ -92,17 +130,6 @@ function getActiveRootSpan() {
92
130
  const op = core.spanToJSON(rootSpan).op;
93
131
  return op === "navigation" || op === "pageload" ? rootSpan : void 0;
94
132
  }
95
- function getParameterizedRoute(routerState) {
96
- const lastMatch = routerState.matches[routerState.matches.length - 1];
97
- return normalizePathname(lastMatch?.route.path ?? routerState.location.pathname);
98
- }
99
- function normalizePathname(pathname) {
100
- let normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
101
- if (normalized.length > 1 && normalized.endsWith("/")) {
102
- normalized = normalized.slice(0, -1);
103
- }
104
- return normalized;
105
- }
106
133
 
107
134
  exports.instrumentHydratedRouter = instrumentHydratedRouter;
108
135
  //# sourceMappingURL=hydratedRouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydratedRouter.js","sources":["../../../src/client/hydratedRouter.ts"],"sourcesContent":["import { startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { DataRouter, RouterState } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isClientInstrumentationApiUsed } from './createClientInstrumentation';\nimport { resolveNavigateArg } from './utils';\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\nconst MAX_RETRIES = 40; // 2 seconds at 50ms interval\n\n/**\n * Instruments the React Router Data Router for pageloads and navigation.\n *\n * This function waits for the router to be available after hydration, then:\n * 1. Updates the pageload transaction with parameterized route info\n * 2. Patches router.navigate() to create navigation transactions\n * 3. Subscribes to router state changes to update navigation transactions with parameterized routes\n */\nexport function instrumentHydratedRouter(): void {\n function trySubscribe(): boolean {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n\n if (router) {\n // The first time we hit the router, we try to update the pageload transaction\n const pageloadSpan = getActiveRootSpan();\n\n if (pageloadSpan) {\n const pageloadName = spanToJSON(pageloadSpan).description;\n const parameterizePageloadRoute = getParameterizedRoute(router.state);\n if (\n pageloadName &&\n // this event is for the currently active pageload\n normalizePathname(router.state.location.pathname) === normalizePathname(pageloadName)\n ) {\n pageloadSpan.updateName(parameterizePageloadRoute);\n pageloadSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react_router',\n });\n }\n }\n\n // Patching navigate for creating accurate navigation transactions\n if (typeof router.navigate === 'function') {\n const originalNav = router.navigate.bind(router);\n router.navigate = function sentryPatchedNavigate(...args) {\n // Skip if instrumentation API is enabled (it handles navigation spans itself)\n if (!isClientInstrumentationApiUsed()) {\n maybeCreateNavigationTransaction(resolveNavigateArg(args[0]) || '<unknown route>', 'url');\n }\n return originalNav(...args);\n };\n }\n\n // Subscribe to router state changes to update navigation transactions (and any pageload\n // whose route info only became available after `trySubscribe`, e.g. lazy routes) with the\n // parameterized route.\n router.subscribe(newState => {\n const rootSpan = getActiveRootSpan();\n\n if (!rootSpan) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n // When the instrumentation API is active, navigation roots are parameterized\n // by the native route hooks\n if (\n rootSpanJson.op === 'navigation' &&\n isClientInstrumentationApiUsed() &&\n rootSpanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'route'\n ) {\n return;\n }\n\n const rootSpanName = rootSpanJson.description;\n const parameterizedRoute = getParameterizedRoute(newState);\n\n if (\n rootSpanName &&\n newState.navigation.state === 'idle' && // navigation has completed\n // this event is for the currently active root span\n normalizePathname(newState.location.pathname) === normalizePathname(rootSpanName)\n ) {\n rootSpan.updateName(parameterizedRoute);\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n }\n });\n return true;\n }\n return false;\n }\n\n // Wait until the router is available (since the SDK loads before hydration)\n if (!trySubscribe()) {\n let retryCount = 0;\n // Retry until the router is available or max retries reached\n const interval = setInterval(() => {\n if (trySubscribe() || retryCount >= MAX_RETRIES) {\n if (retryCount >= MAX_RETRIES) {\n DEBUG_BUILD && debug.warn('Unable to instrument React Router: router not found after hydration.');\n }\n clearInterval(interval);\n }\n retryCount++;\n }, 50);\n }\n}\n\nfunction maybeCreateNavigationTransaction(name: string, source: 'url' | 'route'): Span | undefined {\n const client = getClient();\n\n if (!client) {\n return undefined;\n }\n\n return startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router',\n },\n });\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return undefined;\n }\n\n const rootSpan = getRootSpan(activeSpan);\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n\nfunction getParameterizedRoute(routerState: RouterState): string {\n const lastMatch = routerState.matches[routerState.matches.length - 1];\n return normalizePathname(lastMatch?.route.path ?? routerState.location.pathname);\n}\n\nfunction normalizePathname(pathname: string): string {\n // Ensure it starts with a single slash\n let normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;\n // Remove trailing slash unless it's the root\n if (normalized.length > 1 && normalized.endsWith('/')) {\n normalized = normalized.slice(0, -1);\n }\n return normalized;\n}\n"],"names":["GLOBAL_OBJ","spanToJSON","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","isClientInstrumentationApiUsed","resolveNavigateArg","DEBUG_BUILD","debug","getClient","startBrowserTracingNavigationSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","getActiveSpan","getRootSpan"],"mappings":";;;;;;;;AAkBA,MAAM,2BAAA,GAA8BA,eAAA;AAIpC,MAAM,WAAA,GAAc,EAAA;AAUb,SAAS,wBAAA,GAAiC;AAC/C,EAAA,SAAS,YAAA,GAAwB;AAC/B,IAAA,MAAM,SAAS,2BAAA,CAA4B,uBAAA;AAE3C,IAAA,IAAI,MAAA,EAAQ;AAEV,MAAA,MAAM,eAAe,iBAAA,EAAkB;AAEvC,MAAA,IAAI,YAAA,EAAc;AAChB,QAAA,MAAM,YAAA,GAAeC,eAAA,CAAW,YAAY,CAAA,CAAE,WAAA;AAC9C,QAAA,MAAM,yBAAA,GAA4B,qBAAA,CAAsB,MAAA,CAAO,KAAK,CAAA;AACpE,QAAA,IACE,YAAA;AAAA,QAEA,iBAAA,CAAkB,OAAO,KAAA,CAAM,QAAA,CAAS,QAAQ,CAAA,KAAM,iBAAA,CAAkB,YAAY,CAAA,EACpF;AACA,UAAA,YAAA,CAAa,WAAW,yBAAyB,CAAA;AACjD,UAAA,YAAA,CAAa,aAAA,CAAc;AAAA,YACzB,CAACC,qCAAgC,GAAG,OAAA;AAAA,YACpC,CAACC,qCAAgC,GAAG;AAAA,WACrC,CAAA;AAAA,QACH;AAAA,MACF;AAGA,MAAA,IAAI,OAAO,MAAA,CAAO,QAAA,KAAa,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EAAA,OAAO,kBAAkB,SAAA,EAAW,KAAA,CAAM,IAAA,IAAQ,WAAA,CAAY,SAAS,QAAQ,CAAA;AACjF;AAEA,SAAS,kBAAkB,QAAA,EAA0B;AAEnD,EAAA,IAAI,aAAa,QAAA,CAAS,UAAA,CAAW,GAAG,CAAA,GAAI,QAAA,GAAW,IAAI,QAAQ,CAAA,CAAA;AAEnE,EAAA,IAAI,WAAW,MAAA,GAAS,CAAA,IAAK,UAAA,CAAW,QAAA,CAAS,GAAG,CAAA,EAAG;AACrD,IAAA,UAAA,GAAa,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,UAAA;AACT;;;;"}
1
+ {"version":3,"file":"hydratedRouter.js","sources":["../../../src/client/hydratedRouter.ts"],"sourcesContent":["import { getAbsoluteUrl, startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n isThenable,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { DataRouter } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isClientInstrumentationApiUsed } from './createClientInstrumentation';\nimport {\n finalizeNavigationSpanFromRouterState,\n getParameterizedRoute,\n normalizePathname,\n resolveNavigateAbsoluteUrl,\n resolveNavigateArg,\n} from './utils';\nimport { URL_PATH, URL_TEMPLATE } from '@sentry/conventions/attributes';\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\nconst MAX_RETRIES = 40; // 2 seconds at 50ms interval\n\n/**\n * Instruments the React Router Data Router for pageloads and navigation.\n *\n * This function waits for the router to be available after hydration, then:\n * 1. Updates the pageload transaction with parameterized route info\n * 2. Patches router.navigate() to create navigation transactions\n * 3. Subscribes to router state changes to update navigation transactions with parameterized routes\n */\nexport function instrumentHydratedRouter(): void {\n function trySubscribe(): boolean {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n\n if (router) {\n // The first time we hit the router, we try to update the pageload transaction\n const pageloadSpan = getActiveRootSpan();\n\n if (pageloadSpan) {\n const pageloadName = spanToJSON(pageloadSpan).description;\n const parameterizePageloadRoute = getParameterizedRoute(router.state);\n if (\n pageloadName &&\n // this event is for the currently active pageload\n normalizePathname(router.state.location.pathname) === normalizePathname(pageloadName)\n ) {\n pageloadSpan.updateName(parameterizePageloadRoute);\n pageloadSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react_router',\n [URL_TEMPLATE]: parameterizePageloadRoute,\n });\n }\n }\n\n // Patching navigate for creating accurate navigation transactions\n if (typeof router.navigate === 'function') {\n const originalNav = router.navigate.bind(router);\n router.navigate = function sentryPatchedNavigate(...args) {\n // Skip if instrumentation API is enabled (it handles navigation spans itself)\n if (!isClientInstrumentationApiUsed()) {\n const target = args[0];\n\n if (typeof target === 'number') {\n // navigate(0) triggers a reload, not a route change — skip span creation\n if (target !== 0) {\n const currentPathname = WINDOW.location?.pathname || '/';\n const navigationSpan = maybeCreateNavigationTransaction(\n currentPathname,\n getAbsoluteUrl(currentPathname),\n 'url',\n );\n\n const result = originalNav(...args);\n\n // Numeric navigations (`navigate(-1)`/`navigate(1)`) don't carry a destination\n // path, so we can only resolve the real URL/route once the router has settled.\n if (navigationSpan) {\n // Finalize from the (updated) router state after navigation completes, in both\n // the resolve and reject paths, so a rejected navigation still ends up with the\n // correct URL attributes instead of the placeholder start pathname.\n if (isThenable(result)) {\n result.then(\n () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state),\n () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state),\n );\n } else {\n finalizeNavigationSpanFromRouterState(navigationSpan, router.state);\n }\n }\n\n return result;\n }\n } else {\n maybeCreateNavigationTransaction(\n resolveNavigateArg(target) || '<unknown route>',\n resolveNavigateAbsoluteUrl(target),\n 'url',\n );\n }\n }\n return originalNav(...args);\n };\n }\n\n // Subscribe to router state changes to update navigation transactions (and any pageload\n // whose route info only became available after `trySubscribe`, e.g. lazy routes) with the\n // parameterized route.\n router.subscribe(newState => {\n const rootSpan = getActiveRootSpan();\n\n if (!rootSpan) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n // When the instrumentation API is active, navigation roots are parameterized\n // by the native route hooks\n if (\n rootSpanJson.op === 'navigation' &&\n isClientInstrumentationApiUsed() &&\n rootSpanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'route'\n ) {\n return;\n }\n\n const rootSpanName = rootSpanJson.description;\n const parameterizedRoute = getParameterizedRoute(newState);\n const spanPathname = rootSpanJson.data?.[URL_PATH] as string | undefined;\n const destinationPathname = normalizePathname(newState.location.pathname);\n\n if (\n rootSpanName &&\n newState.navigation.state === 'idle' && // navigation has completed\n // this event is for the currently active root span\n (destinationPathname === normalizePathname(rootSpanName) ||\n (spanPathname && destinationPathname === normalizePathname(spanPathname)))\n ) {\n rootSpan.updateName(parameterizedRoute);\n rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: parameterizedRoute });\n }\n });\n return true;\n }\n return false;\n }\n\n // Wait until the router is available (since the SDK loads before hydration)\n if (!trySubscribe()) {\n let retryCount = 0;\n // Retry until the router is available or max retries reached\n const interval = setInterval(() => {\n if (trySubscribe() || retryCount >= MAX_RETRIES) {\n if (retryCount >= MAX_RETRIES) {\n DEBUG_BUILD && debug.warn('Unable to instrument React Router: router not found after hydration.');\n }\n clearInterval(interval);\n }\n retryCount++;\n }, 50);\n }\n}\n\nfunction maybeCreateNavigationTransaction(name: string, url: string, source: 'url' | 'route'): Span | undefined {\n const client = getClient();\n\n if (!client) {\n return undefined;\n }\n\n return startBrowserTracingNavigationSpan(\n client,\n {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router',\n ...(source === 'route' ? { [URL_TEMPLATE]: name } : {}),\n },\n },\n { url },\n );\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return undefined;\n }\n\n const rootSpan = getRootSpan(activeSpan);\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":["GLOBAL_OBJ","spanToJSON","getParameterizedRoute","normalizePathname","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","URL_TEMPLATE","isClientInstrumentationApiUsed","getAbsoluteUrl","isThenable","finalizeNavigationSpanFromRouterState","resolveNavigateArg","resolveNavigateAbsoluteUrl","URL_PATH","DEBUG_BUILD","debug","getClient","startBrowserTracingNavigationSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","getActiveSpan","getRootSpan"],"mappings":";;;;;;;;;AA0BA,MAAM,2BAAA,GAA8BA,eAAA;AAIpC,MAAM,MAAA,GAASA,eAAA;AAEf,MAAM,WAAA,GAAc,EAAA;AAUb,SAAS,wBAAA,GAAiC;AAC/C,EAAA,SAAS,YAAA,GAAwB;AAC/B,IAAA,MAAM,SAAS,2BAAA,CAA4B,uBAAA;AAE3C,IAAA,IAAI,MAAA,EAAQ;AAEV,MAAA,MAAM,eAAe,iBAAA,EAAkB;AAEvC,MAAA,IAAI,YAAA,EAA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,GACR;AACF;AAEA,SAAS,iBAAA,GAAsC;AAC7C,EAAA,MAAM,aAAac,kBAAA,EAAc;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,GAAWC,iBAAY,UAAU,CAAA;AAEvC,EAAA,MAAM,EAAA,GAAKnB,eAAA,CAAW,QAAQ,CAAA,CAAE,EAAA;AAGhC,EAAA,OAAO,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,GAAa,QAAA,GAAW,MAAA;AAC/D;;;;"}
@@ -1,7 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
+ const browser = require('@sentry/browser');
3
4
  const core = require('@sentry/core');
5
+ const attributes = require('@sentry/conventions/attributes');
4
6
 
7
+ const WINDOW = core.GLOBAL_OBJ;
8
+ const GLOBAL_OBJ_WITH_DATA_ROUTER = core.GLOBAL_OBJ;
5
9
  function resolveNavigateArg(target) {
6
10
  if (typeof target !== "object" || target === null) {
7
11
  return String(target);
@@ -10,8 +14,89 @@ function resolveNavigateArg(target) {
10
14
  if (typeof pathname === "string") {
11
15
  return pathname || "/";
12
16
  }
13
- return core.GLOBAL_OBJ.location?.pathname || "/";
17
+ return WINDOW.location?.pathname || "/";
18
+ }
19
+ function resolveNavigateUrl(target) {
20
+ if (typeof target !== "object" || target === null) {
21
+ return String(target);
22
+ }
23
+ const { pathname, search, hash } = target;
24
+ const path = typeof pathname === "string" && pathname !== "" ? pathname : WINDOW.location?.pathname || "/";
25
+ return `${path}${typeof search === "string" ? search : ""}${typeof hash === "string" ? hash : ""}`;
26
+ }
27
+ function getNavigateBaseUrl(currentUrl) {
28
+ const origin = WINDOW.location?.origin || "http://localhost";
29
+ let pathname = WINDOW.location?.pathname;
30
+ if (!pathname && currentUrl) {
31
+ try {
32
+ pathname = new URL(currentUrl, origin).pathname;
33
+ } catch {
34
+ pathname = currentUrl.startsWith("/") ? currentUrl : `/${currentUrl}`;
35
+ }
36
+ }
37
+ pathname = pathname || "/";
38
+ const directory = pathname.endsWith("/") ? pathname : `${pathname}/`;
39
+ return `${origin}${directory}`;
40
+ }
41
+ function resolveNavigateAbsoluteUrl(target, currentUrl) {
42
+ const destination = resolveNavigateUrl(target);
43
+ try {
44
+ const resolved = new URL(destination, getNavigateBaseUrl(currentUrl));
45
+ return browser.getAbsoluteUrl(`${resolved.pathname}${resolved.search}${resolved.hash}`);
46
+ } catch {
47
+ return browser.getAbsoluteUrl(destination);
48
+ }
49
+ }
50
+ function updateNavigationSpanUrlFromLocation(span) {
51
+ if (!WINDOW.location) {
52
+ return;
53
+ }
54
+ const { pathname, search = "", hash = "" } = WINDOW.location;
55
+ const destinationUrl = browser.getAbsoluteUrl(`${pathname}${search}${hash}`);
56
+ span.updateName(pathname);
57
+ span.setAttributes({
58
+ [attributes.URL_PATH]: pathname,
59
+ [attributes.URL_FULL]: destinationUrl
60
+ });
61
+ }
62
+ function normalizePathname(pathname) {
63
+ let normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
64
+ if (normalized.length > 1 && normalized.endsWith("/")) {
65
+ normalized = normalized.slice(0, -1);
66
+ }
67
+ return normalized;
68
+ }
69
+ function getParameterizedRoute(routerState) {
70
+ const lastMatch = routerState.matches[routerState.matches.length - 1];
71
+ return normalizePathname(lastMatch?.route.path || routerState.location.pathname);
72
+ }
73
+ function finalizeNavigationSpanFromRouterState(span, routerState) {
74
+ updateNavigationSpanUrlFromLocation(span);
75
+ if (!WINDOW.location) {
76
+ return;
77
+ }
78
+ const { pathname } = WINDOW.location;
79
+ if (routerState.navigation?.state === "idle" && normalizePathname(routerState.location.pathname) === normalizePathname(pathname)) {
80
+ const parameterizedRoute = getParameterizedRoute(routerState);
81
+ span.updateName(parameterizedRoute);
82
+ span.setAttributes({ [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [attributes.URL_TEMPLATE]: parameterizedRoute });
83
+ }
84
+ }
85
+ function finalizeNavigationSpanFromHydratedRouter(span) {
86
+ const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;
87
+ if (router) {
88
+ finalizeNavigationSpanFromRouterState(span, router.state);
89
+ } else {
90
+ updateNavigationSpanUrlFromLocation(span);
91
+ }
14
92
  }
15
93
 
94
+ exports.finalizeNavigationSpanFromHydratedRouter = finalizeNavigationSpanFromHydratedRouter;
95
+ exports.finalizeNavigationSpanFromRouterState = finalizeNavigationSpanFromRouterState;
96
+ exports.getParameterizedRoute = getParameterizedRoute;
97
+ exports.normalizePathname = normalizePathname;
98
+ exports.resolveNavigateAbsoluteUrl = resolveNavigateAbsoluteUrl;
16
99
  exports.resolveNavigateArg = resolveNavigateArg;
100
+ exports.resolveNavigateUrl = resolveNavigateUrl;
101
+ exports.updateNavigationSpanUrlFromLocation = updateNavigationSpanUrlFromLocation;
17
102
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/client/utils.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/**\n * Resolves a navigate argument to a pathname string.\n *\n * React Router's navigate() accepts a string, number, or a To object ({ pathname, search, hash }).\n * All fields in the To object are optional (Partial<Path>), so we need to detect object args\n * to avoid \"[object Object]\" transaction names.\n */\nexport function resolveNavigateArg(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n // Object `to` with pathname\n const pathname = (target as Record<string, unknown>).pathname;\n if (typeof pathname === 'string') {\n return pathname || '/';\n }\n\n // Object `to` without pathname - navigation stays on current path\n return (GLOBAL_OBJ as typeof GLOBAL_OBJ & Window).location?.pathname || '/';\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AASO,SAAS,mBAAmB,MAAA,EAAyB;AAC1D,EAAA,IAAI,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,KAAW,IAAA,EAAM;AAEjD,IAAA,OAAO,OAAO,MAAM,CAAA;AAAA,EACtB;AAGA,EAAA,MAAM,WAAY,MAAA,CAAmC,QAAA;AACrD,EAAA,IAAI,OAAO,aAAa,QAAA,EAAU;AAChC,IAAA,OAAO,QAAA,IAAY,GAAA;AAAA,EACrB;AAGA,EAAA,OAAQA,eAAA,CAA0C,UAAU,QAAA,IAAY,GAAA;AAC1E;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/client/utils.ts"],"sourcesContent":["import { getAbsoluteUrl } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport { URL_FULL, URL_PATH, URL_TEMPLATE } from '@sentry/conventions/attributes';\nimport type { DataRouter, RouterState } from 'react-router';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\n/**\n * Resolves a navigate argument to a pathname string.\n *\n * React Router's navigate() accepts a string, number, or a To object ({ pathname, search, hash }).\n * All fields in the To object are optional (Partial<Path>), so we need to detect object args\n * to avoid \"[object Object]\" transaction names.\n */\nexport function resolveNavigateArg(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n // Object `to` with pathname\n const pathname = (target as Record<string, unknown>).pathname;\n if (typeof pathname === 'string') {\n return pathname || '/';\n }\n\n // Object `to` without pathname - navigation stays on current path\n return WINDOW.location?.pathname || '/';\n}\n\n/**\n * Resolves a navigate argument to the full destination path, preserving `search`/`hash` from a\n * To object. Unlike `resolveNavigateArg` (used for span/route naming, which should stay a bare\n * path), this is used to derive `url.full`/`url.path`, which should reflect the actual\n * destination the user is navigating to, including any query string.\n */\nexport function resolveNavigateUrl(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n const { pathname, search, hash } = target as Record<string, unknown>;\n const path = typeof pathname === 'string' && pathname !== '' ? pathname : WINDOW.location?.pathname || '/';\n\n return `${path}${typeof search === 'string' ? search : ''}${typeof hash === 'string' ? hash : ''}`;\n}\n\nfunction getNavigateBaseUrl(currentUrl?: string): string {\n const origin = WINDOW.location?.origin || 'http://localhost';\n\n // Prefer the live pathname, but fall back to the hook-provided `currentUrl` (which may be a full\n // URL or a bare path) when `location` is unavailable (e.g. SSR/non-browser environments).\n let pathname = WINDOW.location?.pathname;\n if (!pathname && currentUrl) {\n try {\n pathname = new URL(currentUrl, origin).pathname;\n } catch {\n pathname = currentUrl.startsWith('/') ? currentUrl : `/${currentUrl}`;\n }\n }\n pathname = pathname || '/';\n\n // React Router resolves relative navigate targets against the current path treated as a\n // *directory* (it appends segments), whereas the WHATWG `URL` parser treats the last path\n // segment as a file and drops it. Enforce a trailing slash so relative resolution matches\n // React Router, e.g. `navigate('ssr')` from `/performance` -> `/performance/ssr` (not `/ssr`).\n const directory = pathname.endsWith('/') ? pathname : `${pathname}/`;\n\n return `${origin}${directory}`;\n}\n\n/**\n * Resolves a navigate argument to an absolute URL for `url.full`/`url.path`, correctly handling\n * relative targets (no leading slash) by resolving them against the current URL instead of the\n * document origin alone.\n */\nexport function resolveNavigateAbsoluteUrl(target: unknown, currentUrl?: string): string {\n const destination = resolveNavigateUrl(target);\n\n try {\n const resolved = new URL(destination, getNavigateBaseUrl(currentUrl));\n return getAbsoluteUrl(`${resolved.pathname}${resolved.search}${resolved.hash}`);\n } catch {\n return getAbsoluteUrl(destination);\n }\n}\n\n/**\n * Updates a navigation span's name and `url.path`/`url.full` from the current `location`.\n */\nexport function updateNavigationSpanUrlFromLocation(span: Span): void {\n if (!WINDOW.location) {\n return;\n }\n\n const { pathname, search = '', hash = '' } = WINDOW.location;\n const destinationUrl = getAbsoluteUrl(`${pathname}${search}${hash}`);\n\n span.updateName(pathname);\n span.setAttributes({\n [URL_PATH]: pathname,\n [URL_FULL]: destinationUrl,\n });\n}\n\nexport function normalizePathname(pathname: string): string {\n let normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;\n if (normalized.length > 1 && normalized.endsWith('/')) {\n normalized = normalized.slice(0, -1);\n }\n return normalized;\n}\n\nexport function getParameterizedRoute(routerState: RouterState): string {\n const lastMatch = routerState.matches[routerState.matches.length - 1];\n return normalizePathname(lastMatch?.route.path || routerState.location.pathname);\n}\n\n/**\n * Updates a navigation span's URL attributes and parameterizes its name from the router state.\n * Used after numeric navigations (`navigate(-1)` / `navigate(1)`) where route hooks may not\n * supply a pattern (e.g. index routes).\n *\n * `url.path` reflects raw `location.pathname` (may include a trailing slash when the server\n * redirects index routes), while `url.template` is normalized without trailing slashes.\n */\nexport function finalizeNavigationSpanFromRouterState(span: Span, routerState: RouterState): void {\n updateNavigationSpanUrlFromLocation(span);\n\n if (!WINDOW.location) {\n return;\n }\n\n const { pathname } = WINDOW.location;\n\n if (\n routerState.navigation?.state === 'idle' &&\n normalizePathname(routerState.location.pathname) === normalizePathname(pathname)\n ) {\n const parameterizedRoute = getParameterizedRoute(routerState);\n span.updateName(parameterizedRoute);\n span.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: parameterizedRoute });\n }\n}\n\n/**\n * Finalizes a navigation span after numeric navigation using the hydrated data router when\n * available, otherwise falls back to URL attributes from `location` alone.\n */\nexport function finalizeNavigationSpanFromHydratedRouter(span: Span): void {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n if (router) {\n finalizeNavigationSpanFromRouterState(span, router.state);\n } else {\n updateNavigationSpanUrlFromLocation(span);\n }\n}\n"],"names":["GLOBAL_OBJ","getAbsoluteUrl","URL_PATH","URL_FULL","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","URL_TEMPLATE"],"mappings":";;;;;;AAMA,MAAM,MAAA,GAASA,eAAA;AAEf,MAAM,2BAAA,GAA8BA,eAAA;AAW7B,SAAS,mBAAmB,MAAA,EAAyB;AAC1D,E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qCAAA,CAAsC,IAAA,EAAM,OAAO,KAAK,CAAA;AAAA,EAC1D,CAAA,MAAO;AACL,IAAA,mCAAA,CAAoC,IAAI,CAAA;AAAA,EAC1C;AACF;;;;;;;;;;;"}
@@ -1,8 +1,9 @@
1
- import { startBrowserTracingNavigationSpan } from '@sentry/browser';
1
+ import { startBrowserTracingNavigationSpan, getAbsoluteUrl } from '@sentry/browser';
2
2
  import { debug, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SPAN_STATUS_ERROR, GLOBAL_OBJ, getClient, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, getRootSpan, spanToJSON, updateSpanName } from '@sentry/core';
3
3
  import { DEBUG_BUILD } from '../common/debug-build.js';
4
4
  import { captureInstrumentationError, getPathFromRequest, normalizeRoutePath, getPattern } from '../common/utils.js';
5
- import { resolveNavigateArg } from './utils.js';
5
+ import { updateNavigationSpanUrlFromLocation, finalizeNavigationSpanFromHydratedRouter, resolveNavigateArg, resolveNavigateAbsoluteUrl } from './utils.js';
6
+ import { URL_TEMPLATE } from '@sentry/conventions/attributes';
6
7
 
7
8
  const WINDOW = GLOBAL_OBJ;
8
9
  let currentNumericNavigationSpan;
@@ -29,20 +30,24 @@ function createSentryClientInstrumentation(options = {}) {
29
30
  const pathname = WINDOW.location?.pathname || "/";
30
31
  if (currentNumericNavigationSpan) {
31
32
  if (currentNumericNavigationSpan.isRecording()) {
32
- currentNumericNavigationSpan.updateName(pathname);
33
+ updateNavigationSpanUrlFromLocation(currentNumericNavigationSpan);
33
34
  }
34
35
  currentNumericNavigationSpan = void 0;
35
36
  return;
36
37
  }
37
- startBrowserTracingNavigationSpan(client, {
38
- name: pathname,
39
- attributes: {
40
- [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
41
- [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
42
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
43
- "navigation.type": "browser.popstate"
44
- }
45
- });
38
+ startBrowserTracingNavigationSpan(
39
+ client,
40
+ {
41
+ name: pathname,
42
+ attributes: {
43
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
44
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
45
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
46
+ "navigation.type": "browser.popstate"
47
+ }
48
+ },
49
+ { url: getAbsoluteUrl(pathname) }
50
+ );
46
51
  });
47
52
  DEBUG_BUILD && debug.log("React Router popstate listener registered for browser back/forward navigation.");
48
53
  }
@@ -64,21 +69,25 @@ function createSentryClientInstrumentation(options = {}) {
64
69
  if (client2) {
65
70
  const navigationType = info.to < 0 ? "router.back" : "router.forward";
66
71
  const currentPathname = WINDOW.location?.pathname || info.currentUrl;
67
- navigationSpan2 = startBrowserTracingNavigationSpan(client2, {
68
- name: currentPathname,
69
- attributes: {
70
- [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
71
- [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
72
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
73
- "navigation.type": navigationType
74
- }
75
- });
72
+ navigationSpan2 = startBrowserTracingNavigationSpan(
73
+ client2,
74
+ {
75
+ name: currentPathname,
76
+ attributes: {
77
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
78
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
79
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
80
+ "navigation.type": navigationType
81
+ }
82
+ },
83
+ { url: getAbsoluteUrl(currentPathname) }
84
+ );
76
85
  currentNumericNavigationSpan = navigationSpan2;
77
86
  }
78
87
  try {
79
88
  const result2 = await callNavigate();
80
89
  if (navigationSpan2 && WINDOW.location) {
81
- navigationSpan2.updateName(WINDOW.location.pathname);
90
+ finalizeNavigationSpanFromHydratedRouter(navigationSpan2);
82
91
  }
83
92
  if (result2.status === "error" && result2.error instanceof Error) {
84
93
  if (navigationSpan2) {
@@ -97,15 +106,19 @@ function createSentryClientInstrumentation(options = {}) {
97
106
  const toPath = resolveNavigateArg(info.to);
98
107
  let navigationSpan;
99
108
  if (client) {
100
- navigationSpan = startBrowserTracingNavigationSpan(client, {
101
- name: toPath,
102
- attributes: {
103
- [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
104
- [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
105
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
106
- "navigation.type": "router.navigate"
107
- }
108
- });
109
+ navigationSpan = startBrowserTracingNavigationSpan(
110
+ client,
111
+ {
112
+ name: toPath,
113
+ attributes: {
114
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
115
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
116
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router.instrumentation_api",
117
+ "navigation.type": "router.navigate"
118
+ }
119
+ },
120
+ { url: resolveNavigateAbsoluteUrl(info.to, info.currentUrl) }
121
+ );
109
122
  }
110
123
  const result = await callNavigate();
111
124
  if (result.status === "error" && result.error instanceof Error) {
@@ -259,7 +272,7 @@ function updateRootSpanRoute(routeName, hasPattern) {
259
272
  return;
260
273
  }
261
274
  updateSpanName(rootSpan, routeName);
262
- rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route");
275
+ rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [URL_TEMPLATE]: routeName });
263
276
  }
264
277
  function isClientInstrumentationApiUsed() {
265
278
  return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];
@@ -1 +1 @@
1
- {"version":3,"file":"createClientInstrumentation.js","sources":["../../../src/client/createClientInstrumentation.ts"],"sourcesContent":["import { startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { ClientInstrumentation, InstrumentableRoute, InstrumentableRouter } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport { resolveNavigateArg } from './utils';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\n// Tracks active numeric navigation span to prevent duplicate spans when popstate fires\nlet currentNumericNavigationSpan: Span | undefined;\n\n// Per-request middleware counters, keyed by Request\nconst middlewareCountersMap = new WeakMap<object, Record<string, number>>();\n\nconst SENTRY_CLIENT_INSTRUMENTATION_FLAG = '__sentryReactRouterClientInstrumentationUsed';\n// Intentionally never reset - once set, instrumentation API handles all navigations for the session.\nconst SENTRY_NAVIGATE_HOOK_INVOKED_FLAG = '__sentryReactRouterNavigateHookInvoked';\nconst SENTRY_POPSTATE_LISTENER_ADDED_FLAG = '__sentryReactRouterPopstateListenerAdded';\n\ntype GlobalObjWithFlags = typeof GLOBAL_OBJ & {\n [SENTRY_CLIENT_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_NAVIGATE_HOOK_INVOKED_FLAG]?: boolean;\n [SENTRY_POPSTATE_LISTENER_ADDED_FLAG]?: boolean;\n};\n\nconst GLOBAL_WITH_FLAGS = GLOBAL_OBJ as GlobalObjWithFlags;\n\n/**\n * Options for creating Sentry client instrumentation.\n */\nexport interface CreateSentryClientInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * Set to `false` to avoid duplicates if using custom error handlers.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry client instrumentation for React Router's instrumentation API.\n */\nexport function createSentryClientInstrumentation(\n options: CreateSentryClientInstrumentationOptions = {},\n): ClientInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router client instrumentation API created.');\n\n return {\n router(router: InstrumentableRouter) {\n // Set the flag when React Router actually invokes our instrumentation.\n // This ensures the flag is only set in Library Mode (where hooks run),\n // not in Framework Mode (where hooks are never called).\n // See: https://github.com/remix-run/react-router/discussions/13749\n GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG] = true;\n DEBUG_BUILD && debug.log('React Router client instrumentation API router hook registered.');\n\n // Add popstate listener for browser back/forward navigation (persists for session, one listener only)\n if (!GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] && WINDOW.addEventListener) {\n GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] = true;\n\n WINDOW.addEventListener('popstate', () => {\n const client = getClient();\n if (!client) {\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n const pathname = WINDOW.location?.pathname || '/';\n\n // If there's an active numeric navigation span, update it instead of creating a duplicate\n if (currentNumericNavigationSpan) {\n if (currentNumericNavigationSpan.isRecording()) {\n currentNumericNavigationSpan.updateName(pathname);\n }\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n // Only create a new span for actual browser back/forward button clicks\n startBrowserTracingNavigationSpan(client, {\n name: pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'browser.popstate',\n },\n });\n });\n\n DEBUG_BUILD && debug.log('React Router popstate listener registered for browser back/forward navigation.');\n }\n\n router.instrument({\n async navigate(callNavigate, info) {\n // navigate(0) triggers a page reload - skip span creation, but still capture errors\n // (navigation can be rejected before reload, e.g., by a navigation guard)\n if (info.to === 0) {\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': info.currentUrl,\n });\n }\n return;\n }\n\n GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG] = true;\n\n // Handle numeric navigations (navigate(-1), navigate(1), etc.)\n if (typeof info.to === 'number') {\n const client = getClient();\n let navigationSpan;\n\n if (client) {\n const navigationType = info.to < 0 ? 'router.back' : 'router.forward';\n const currentPathname = WINDOW.location?.pathname || info.currentUrl;\n\n navigationSpan = startBrowserTracingNavigationSpan(client, {\n name: currentPathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': navigationType,\n },\n });\n\n // Store ref so popstate listener can update it instead of creating a duplicate\n currentNumericNavigationSpan = navigationSpan;\n }\n\n try {\n const result = await callNavigate();\n\n if (navigationSpan && WINDOW.location) {\n navigationSpan.updateName(WINDOW.location.pathname);\n }\n\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': WINDOW.location?.pathname || info.currentUrl,\n });\n }\n } finally {\n currentNumericNavigationSpan = undefined;\n }\n return;\n }\n\n // Handle string/object navigations (e.g., navigate('/about') or navigate({ pathname: '/about' }))\n const client = getClient();\n const toPath = resolveNavigateArg(info.to);\n let navigationSpan;\n\n if (client) {\n navigationSpan = startBrowserTracingNavigationSpan(client, {\n name: toPath,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'router.navigate',\n },\n });\n }\n\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': toPath,\n });\n }\n return;\n },\n\n async fetch(callFetch, info) {\n await startSpan(\n {\n name: `Fetcher ${info.fetcherKey}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.fetcher',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callFetch();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.fetcher', {\n 'http.url': info.href,\n });\n }\n },\n );\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n // Parameterize the active navigation root span. (Route hooks don't fire on initial\n // pageload, so this only affects navigations.)\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_loader', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_action', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const routePattern = normalizeRoutePath(getPattern(info)) || urlPath;\n\n let counters = middlewareCountersMap.get(info.request);\n if (!counters) {\n counters = {};\n middlewareCountersMap.set(info.request, counters);\n }\n\n const middlewareIndex = counters[routeId] ?? 0;\n counters[routeId] = middlewareIndex + 1;\n\n await startSpan(\n {\n name: `middleware ${routeId}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n 'http.route': routePattern,\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_middleware', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\n/**\n * Updates the active navigation/pageload root span name with the parameterized route, so the\n * transaction reflects the parameterized route pattern (e.g. `/users/:id`).\n */\nfunction updateRootSpanRoute(routeName: string, hasPattern: boolean): void {\n if (!hasPattern) {\n return;\n }\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n if (!rootSpan) {\n return;\n }\n\n const { op } = spanToJSON(rootSpan);\n if (op !== 'navigation' && op !== 'pageload') {\n return;\n }\n\n updateSpanName(rootSpan, routeName);\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n}\n\n/**\n * Check if React Router's instrumentation API is being used on the client.\n */\nexport function isClientInstrumentationApiUsed(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Check if React Router's instrumentation API's navigate hook was invoked.\n */\nexport function isNavigateHookInvoked(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG];\n}\n"],"names":["result","client","navigationSpan"],"mappings":";;;;;;AAqBA,MAAM,MAAA,GAAS,UAAA;AAGf,IAAI,4BAAA;AAGJ,MAAM,qBAAA,uBAA4B,OAAA,EAAwC;AAE1E,MAAM,kCAAA,GAAqC,8CAAA;AAE3C,MAAM,iCAAA,GAAoC,wCAAA;AAC1C,MAAM,mCAAA,GAAsC,0CAAA;AAQ5C,MAAM,iBAAA,GAAoB,UAAA;AAiBnB,SA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AAM,QAAA,GAAW,UAAA,IAAc,WAAA,CAAY,UAAU,CAAA;AACrD,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,EAAE,EAAA,EAAG,GAAI,UAAA,CAAW,QAAQ,CAAA;AAClC,EAAA,IAAI,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,EAAY;AAC5C,IAAA;AAAA,EACF;AAEA,EAAA,cAAA,CAAe,UAAU,SAAS,CAAA;AAClC,EAAA,QAAA,CAAS,YAAA,CAAa,kCAAkC,OAAO,CAAA;AACjE;AAKO,SAAS,8BAAA,GAA0C;AACxD,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,kCAAkC,CAAA;AAC/D;AAKO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,iCAAiC,CAAA;AAC9D;;;;"}
1
+ {"version":3,"file":"createClientInstrumentation.js","sources":["../../../src/client/createClientInstrumentation.ts"],"sourcesContent":["// oxlint-disable max-lines\nimport { getAbsoluteUrl, startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { ClientInstrumentation, InstrumentableRoute, InstrumentableRouter } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport {\n resolveNavigateAbsoluteUrl,\n resolveNavigateArg,\n finalizeNavigationSpanFromHydratedRouter,\n updateNavigationSpanUrlFromLocation,\n} from './utils';\nimport { URL_TEMPLATE } from '@sentry/conventions/attributes';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\n// Tracks active numeric navigation span to prevent duplicate spans when popstate fires\nlet currentNumericNavigationSpan: Span | undefined;\n\n// Per-request middleware counters, keyed by Request\nconst middlewareCountersMap = new WeakMap<object, Record<string, number>>();\n\nconst SENTRY_CLIENT_INSTRUMENTATION_FLAG = '__sentryReactRouterClientInstrumentationUsed';\n// Intentionally never reset - once set, instrumentation API handles all navigations for the session.\nconst SENTRY_NAVIGATE_HOOK_INVOKED_FLAG = '__sentryReactRouterNavigateHookInvoked';\nconst SENTRY_POPSTATE_LISTENER_ADDED_FLAG = '__sentryReactRouterPopstateListenerAdded';\n\ntype GlobalObjWithFlags = typeof GLOBAL_OBJ & {\n [SENTRY_CLIENT_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_NAVIGATE_HOOK_INVOKED_FLAG]?: boolean;\n [SENTRY_POPSTATE_LISTENER_ADDED_FLAG]?: boolean;\n};\n\nconst GLOBAL_WITH_FLAGS = GLOBAL_OBJ as GlobalObjWithFlags;\n\n/**\n * Options for creating Sentry client instrumentation.\n */\nexport interface CreateSentryClientInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * Set to `false` to avoid duplicates if using custom error handlers.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry client instrumentation for React Router's instrumentation API.\n */\nexport function createSentryClientInstrumentation(\n options: CreateSentryClientInstrumentationOptions = {},\n): ClientInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router client instrumentation API created.');\n\n return {\n router(router: InstrumentableRouter) {\n // Set the flag when React Router actually invokes our instrumentation.\n // This ensures the flag is only set in Library Mode (where hooks run),\n // not in Framework Mode (where hooks are never called).\n // See: https://github.com/remix-run/react-router/discussions/13749\n GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG] = true;\n DEBUG_BUILD && debug.log('React Router client instrumentation API router hook registered.');\n\n // Add popstate listener for browser back/forward navigation (persists for session, one listener only)\n if (!GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] && WINDOW.addEventListener) {\n GLOBAL_WITH_FLAGS[SENTRY_POPSTATE_LISTENER_ADDED_FLAG] = true;\n\n WINDOW.addEventListener('popstate', () => {\n const client = getClient();\n if (!client) {\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n const pathname = WINDOW.location?.pathname || '/';\n\n // If there's an active numeric navigation span, update it instead of creating a duplicate\n if (currentNumericNavigationSpan) {\n if (currentNumericNavigationSpan.isRecording()) {\n updateNavigationSpanUrlFromLocation(currentNumericNavigationSpan);\n }\n currentNumericNavigationSpan = undefined;\n return;\n }\n\n // Only create a new span for actual browser back/forward button clicks\n startBrowserTracingNavigationSpan(\n client,\n {\n name: pathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'browser.popstate',\n },\n },\n { url: getAbsoluteUrl(pathname) },\n );\n });\n\n DEBUG_BUILD && debug.log('React Router popstate listener registered for browser back/forward navigation.');\n }\n\n router.instrument({\n async navigate(callNavigate, info) {\n // navigate(0) triggers a page reload - skip span creation, but still capture errors\n // (navigation can be rejected before reload, e.g., by a navigation guard)\n if (info.to === 0) {\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': info.currentUrl,\n });\n }\n return;\n }\n\n GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG] = true;\n\n // Handle numeric navigations (navigate(-1), navigate(1), etc.)\n if (typeof info.to === 'number') {\n const client = getClient();\n let navigationSpan;\n\n if (client) {\n const navigationType = info.to < 0 ? 'router.back' : 'router.forward';\n const currentPathname = WINDOW.location?.pathname || info.currentUrl;\n\n navigationSpan = startBrowserTracingNavigationSpan(\n client,\n {\n name: currentPathname,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': navigationType,\n },\n },\n { url: getAbsoluteUrl(currentPathname) },\n );\n\n // Store ref so popstate listener can update it instead of creating a duplicate\n currentNumericNavigationSpan = navigationSpan;\n }\n\n try {\n const result = await callNavigate();\n\n if (navigationSpan && WINDOW.location) {\n finalizeNavigationSpanFromHydratedRouter(navigationSpan);\n }\n\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': WINDOW.location?.pathname || info.currentUrl,\n });\n }\n } finally {\n currentNumericNavigationSpan = undefined;\n }\n return;\n }\n\n // Handle string/object navigations (e.g., navigate('/about') or navigate({ pathname: '/about' }))\n const client = getClient();\n const toPath = resolveNavigateArg(info.to);\n let navigationSpan;\n\n if (client) {\n navigationSpan = startBrowserTracingNavigationSpan(\n client,\n {\n name: toPath,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router.instrumentation_api',\n 'navigation.type': 'router.navigate',\n },\n },\n { url: resolveNavigateAbsoluteUrl(info.to, info.currentUrl) },\n );\n }\n\n const result = await callNavigate();\n if (result.status === 'error' && result.error instanceof Error) {\n if (navigationSpan) {\n navigationSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n captureInstrumentationError(result, captureErrors, 'react_router.navigate', {\n 'http.url': toPath,\n });\n }\n return;\n },\n\n async fetch(callFetch, info) {\n await startSpan(\n {\n name: `Fetcher ${info.fetcherKey}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.fetcher',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callFetch();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.fetcher', {\n 'http.url': info.href,\n });\n }\n },\n );\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n // Parameterize the active navigation root span. (Route hooks don't fire on initial\n // pageload, so this only affects navigations.)\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_loader', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = normalizeRoutePath(getPattern(info));\n const routePattern = pattern || urlPath;\n updateRootSpanRoute(routePattern, !!pattern);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_action', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const routePattern = normalizeRoutePath(getPattern(info)) || urlPath;\n\n let counters = middlewareCountersMap.get(info.request);\n if (!counters) {\n counters = {};\n middlewareCountersMap.set(info.request, counters);\n }\n\n const middlewareIndex = counters[routeId] ?? 0;\n counters[routeId] = middlewareIndex + 1;\n\n await startSpan(\n {\n name: `middleware ${routeId}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n 'http.route': routePattern,\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_middleware', {\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.client_lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.client_lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\n/**\n * Updates the active navigation/pageload root span name with the parameterized route, so the\n * transaction reflects the parameterized route pattern (e.g. `/users/:id`).\n */\nfunction updateRootSpanRoute(routeName: string, hasPattern: boolean): void {\n if (!hasPattern) {\n return;\n }\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n if (!rootSpan) {\n return;\n }\n\n const { op } = spanToJSON(rootSpan);\n if (op !== 'navigation' && op !== 'pageload') {\n return;\n }\n\n updateSpanName(rootSpan, routeName);\n rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: routeName });\n}\n\n/**\n * Check if React Router's instrumentation API is being used on the client.\n */\nexport function isClientInstrumentationApiUsed(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_CLIENT_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Check if React Router's instrumentation API's navigate hook was invoked.\n */\nexport function isNavigateHookInvoked(): boolean {\n return !!GLOBAL_WITH_FLAGS[SENTRY_NAVIGATE_HOOK_INVOKED_FLAG];\n}\n"],"names":["result","client","navigationSpan"],"mappings":";;;;;;;AA4BA,MAAM,MAAA,GAAS,UAAA;AAGf,IAAI,4BAAA;AAGJ,MAAM,qBAAA,uBAA4B,OAAA,EAAwC;AAE1E,MAAM,kCAAA,GAAqC,8CAAA;AAE3C,MAAM,iCAAA,GAAoC,wCAAA;AAC1C,MAAM,mCAAA,GAAsC,0CAAA;AAQ5C,MAAM,iBAAA,GAAoB,UAAA;AAiBnB,SAAS,iCAAA,CACd,OAAA,GAAoD,EAAC,EAC9B;AACvB,EAAA,MAAM,EAAE,aAAA,GAAgB,IAAA,EAAK,GAAI,OAAA;AAEjC,EAAA,WAAA,IAAe,KAAA,CAAM,IAAI,kDAAkD,CAAA;AAE3E,EAAA,OAAO;AAAA,IACL,OAAO,MAAA,EAA8B;AAKnC,MAAA,iBAAA,CAAkB,kCAAkC,CAAA,GAAI,IAAA;AACxD,MAAA,WAAA,IAAe,KAAA,CAAM,IAAI,iEAAiE,CAAA;AAG1F,MAAA,IAAI,CAAC,iBAAA,CAAkB,mCAAmC,CAAA,IAAK,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Q,CAAA;AAClC,EAAA,IAAI,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,EAAY;AAC5C,IAAA;AAAA,EACF;AAEA,EAAA,cAAA,CAAe,UAAU,SAAS,CAAA;AAClC,EAAA,QAAA,CAAS,aAAA,CAAc,EAAE,CAAC,gCAAgC,GAAG,SAAS,CAAC,YAAY,GAAG,SAAA,EAAW,CAAA;AACnG;AAKO,SAAS,8BAAA,GAA0C;AACxD,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,kCAAkC,CAAA;AAC/D;AAKO,SAAS,qBAAA,GAAiC;AAC/C,EAAA,OAAO,CAAC,CAAC,iBAAA,CAAkB,iCAAiC,CAAA;AAC9D;;;;"}
@@ -1,10 +1,12 @@
1
- import { startBrowserTracingNavigationSpan } from '@sentry/browser';
2
- import { GLOBAL_OBJ, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, debug, getActiveSpan, getRootSpan, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
1
+ import { getAbsoluteUrl, startBrowserTracingNavigationSpan } from '@sentry/browser';
2
+ import { GLOBAL_OBJ, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isThenable, debug, getActiveSpan, getRootSpan, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
3
3
  import { DEBUG_BUILD } from '../common/debug-build.js';
4
4
  import { isClientInstrumentationApiUsed } from './createClientInstrumentation.js';
5
- import { resolveNavigateArg } from './utils.js';
5
+ import { getParameterizedRoute, normalizePathname, finalizeNavigationSpanFromRouterState, resolveNavigateAbsoluteUrl, resolveNavigateArg } from './utils.js';
6
+ import { URL_TEMPLATE, URL_PATH } from '@sentry/conventions/attributes';
6
7
 
7
8
  const GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ;
9
+ const WINDOW = GLOBAL_OBJ;
8
10
  const MAX_RETRIES = 40;
9
11
  function instrumentHydratedRouter() {
10
12
  function trySubscribe() {
@@ -19,7 +21,8 @@ function instrumentHydratedRouter() {
19
21
  pageloadSpan.updateName(parameterizePageloadRoute);
20
22
  pageloadSpan.setAttributes({
21
23
  [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route",
22
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react_router"
24
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react_router",
25
+ [URL_TEMPLATE]: parameterizePageloadRoute
23
26
  });
24
27
  }
25
28
  }
@@ -27,7 +30,35 @@ function instrumentHydratedRouter() {
27
30
  const originalNav = router.navigate.bind(router);
28
31
  router.navigate = function sentryPatchedNavigate(...args) {
29
32
  if (!isClientInstrumentationApiUsed()) {
30
- maybeCreateNavigationTransaction(resolveNavigateArg(args[0]) || "<unknown route>", "url");
33
+ const target = args[0];
34
+ if (typeof target === "number") {
35
+ if (target !== 0) {
36
+ const currentPathname = WINDOW.location?.pathname || "/";
37
+ const navigationSpan = maybeCreateNavigationTransaction(
38
+ currentPathname,
39
+ getAbsoluteUrl(currentPathname),
40
+ "url"
41
+ );
42
+ const result = originalNav(...args);
43
+ if (navigationSpan) {
44
+ if (isThenable(result)) {
45
+ result.then(
46
+ () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state),
47
+ () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state)
48
+ );
49
+ } else {
50
+ finalizeNavigationSpanFromRouterState(navigationSpan, router.state);
51
+ }
52
+ }
53
+ return result;
54
+ }
55
+ } else {
56
+ maybeCreateNavigationTransaction(
57
+ resolveNavigateArg(target) || "<unknown route>",
58
+ resolveNavigateAbsoluteUrl(target),
59
+ "url"
60
+ );
61
+ }
31
62
  }
32
63
  return originalNav(...args);
33
64
  };
@@ -43,11 +74,13 @@ function instrumentHydratedRouter() {
43
74
  }
44
75
  const rootSpanName = rootSpanJson.description;
45
76
  const parameterizedRoute = getParameterizedRoute(newState);
77
+ const spanPathname = rootSpanJson.data?.[URL_PATH];
78
+ const destinationPathname = normalizePathname(newState.location.pathname);
46
79
  if (rootSpanName && newState.navigation.state === "idle" && // navigation has completed
47
80
  // this event is for the currently active root span
48
- normalizePathname(newState.location.pathname) === normalizePathname(rootSpanName)) {
81
+ (destinationPathname === normalizePathname(rootSpanName) || spanPathname && destinationPathname === normalizePathname(spanPathname))) {
49
82
  rootSpan.updateName(parameterizedRoute);
50
- rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route");
83
+ rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [URL_TEMPLATE]: parameterizedRoute });
51
84
  }
52
85
  });
53
86
  return true;
@@ -67,19 +100,24 @@ function instrumentHydratedRouter() {
67
100
  }, 50);
68
101
  }
69
102
  }
70
- function maybeCreateNavigationTransaction(name, source) {
103
+ function maybeCreateNavigationTransaction(name, url, source) {
71
104
  const client = getClient();
72
105
  if (!client) {
73
106
  return void 0;
74
107
  }
75
- return startBrowserTracingNavigationSpan(client, {
76
- name,
77
- attributes: {
78
- [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
79
- [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
80
- [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router"
81
- }
82
- });
108
+ return startBrowserTracingNavigationSpan(
109
+ client,
110
+ {
111
+ name,
112
+ attributes: {
113
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
114
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
115
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react_router",
116
+ ...{}
117
+ }
118
+ },
119
+ { url }
120
+ );
83
121
  }
84
122
  function getActiveRootSpan() {
85
123
  const activeSpan = getActiveSpan();
@@ -90,17 +128,6 @@ function getActiveRootSpan() {
90
128
  const op = spanToJSON(rootSpan).op;
91
129
  return op === "navigation" || op === "pageload" ? rootSpan : void 0;
92
130
  }
93
- function getParameterizedRoute(routerState) {
94
- const lastMatch = routerState.matches[routerState.matches.length - 1];
95
- return normalizePathname(lastMatch?.route.path ?? routerState.location.pathname);
96
- }
97
- function normalizePathname(pathname) {
98
- let normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
99
- if (normalized.length > 1 && normalized.endsWith("/")) {
100
- normalized = normalized.slice(0, -1);
101
- }
102
- return normalized;
103
- }
104
131
 
105
132
  export { instrumentHydratedRouter };
106
133
  //# sourceMappingURL=hydratedRouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydratedRouter.js","sources":["../../../src/client/hydratedRouter.ts"],"sourcesContent":["import { startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { DataRouter, RouterState } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isClientInstrumentationApiUsed } from './createClientInstrumentation';\nimport { resolveNavigateArg } from './utils';\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\nconst MAX_RETRIES = 40; // 2 seconds at 50ms interval\n\n/**\n * Instruments the React Router Data Router for pageloads and navigation.\n *\n * This function waits for the router to be available after hydration, then:\n * 1. Updates the pageload transaction with parameterized route info\n * 2. Patches router.navigate() to create navigation transactions\n * 3. Subscribes to router state changes to update navigation transactions with parameterized routes\n */\nexport function instrumentHydratedRouter(): void {\n function trySubscribe(): boolean {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n\n if (router) {\n // The first time we hit the router, we try to update the pageload transaction\n const pageloadSpan = getActiveRootSpan();\n\n if (pageloadSpan) {\n const pageloadName = spanToJSON(pageloadSpan).description;\n const parameterizePageloadRoute = getParameterizedRoute(router.state);\n if (\n pageloadName &&\n // this event is for the currently active pageload\n normalizePathname(router.state.location.pathname) === normalizePathname(pageloadName)\n ) {\n pageloadSpan.updateName(parameterizePageloadRoute);\n pageloadSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react_router',\n });\n }\n }\n\n // Patching navigate for creating accurate navigation transactions\n if (typeof router.navigate === 'function') {\n const originalNav = router.navigate.bind(router);\n router.navigate = function sentryPatchedNavigate(...args) {\n // Skip if instrumentation API is enabled (it handles navigation spans itself)\n if (!isClientInstrumentationApiUsed()) {\n maybeCreateNavigationTransaction(resolveNavigateArg(args[0]) || '<unknown route>', 'url');\n }\n return originalNav(...args);\n };\n }\n\n // Subscribe to router state changes to update navigation transactions (and any pageload\n // whose route info only became available after `trySubscribe`, e.g. lazy routes) with the\n // parameterized route.\n router.subscribe(newState => {\n const rootSpan = getActiveRootSpan();\n\n if (!rootSpan) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n // When the instrumentation API is active, navigation roots are parameterized\n // by the native route hooks\n if (\n rootSpanJson.op === 'navigation' &&\n isClientInstrumentationApiUsed() &&\n rootSpanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'route'\n ) {\n return;\n }\n\n const rootSpanName = rootSpanJson.description;\n const parameterizedRoute = getParameterizedRoute(newState);\n\n if (\n rootSpanName &&\n newState.navigation.state === 'idle' && // navigation has completed\n // this event is for the currently active root span\n normalizePathname(newState.location.pathname) === normalizePathname(rootSpanName)\n ) {\n rootSpan.updateName(parameterizedRoute);\n rootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n }\n });\n return true;\n }\n return false;\n }\n\n // Wait until the router is available (since the SDK loads before hydration)\n if (!trySubscribe()) {\n let retryCount = 0;\n // Retry until the router is available or max retries reached\n const interval = setInterval(() => {\n if (trySubscribe() || retryCount >= MAX_RETRIES) {\n if (retryCount >= MAX_RETRIES) {\n DEBUG_BUILD && debug.warn('Unable to instrument React Router: router not found after hydration.');\n }\n clearInterval(interval);\n }\n retryCount++;\n }, 50);\n }\n}\n\nfunction maybeCreateNavigationTransaction(name: string, source: 'url' | 'route'): Span | undefined {\n const client = getClient();\n\n if (!client) {\n return undefined;\n }\n\n return startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router',\n },\n });\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return undefined;\n }\n\n const rootSpan = getRootSpan(activeSpan);\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n\nfunction getParameterizedRoute(routerState: RouterState): string {\n const lastMatch = routerState.matches[routerState.matches.length - 1];\n return normalizePathname(lastMatch?.route.path ?? routerState.location.pathname);\n}\n\nfunction normalizePathname(pathname: string): string {\n // Ensure it starts with a single slash\n let normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;\n // Remove trailing slash unless it's the root\n if (normalized.length > 1 && normalized.endsWith('/')) {\n normalized = normalized.slice(0, -1);\n }\n return normalized;\n}\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,2BAAA,GAA8B,UAAA;AAIpC,MAAM,WAAA,GAAc,EAAA;AAUb,SAAS,wBAAA,GAAiC;AAC/C,EAAA,SAAS,YAAA,GAAwB;AAC/B,I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,UAAA,EAAY;AAAA,MACV,CAAC,gCAAgC,GAAG,MAAA;AAAA,MACpC,CAAC,4BAA4B,GAAG,YAAA;AAAA,MAChC,CAAC,gCAAgC,GAAG;AAAA;AACtC,GACD,CAAA;AACH;AAEA,SAAS,iBAAA,GAAsC;AAC7C,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,GAAW,YAAY,UAAU,CAAA;AAEvC,EAAA,MAAM,EAAA,GAAK,UAAA,CAAW,QAAQ,CAAA,CAAE,EAAA;AAGhC,EAAA,OAAO,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,GAAa,QAAA,GAAW,MAAA;AAC/D;AAEA,SAAS,sBAAsB,WAAA,EAAkC;AAC/D,EAAA,MAAM,YAAY,WAAA,CAAY,OAAA,CAAQ,WAAA,CAAY,OAAA,CAAQ,SAAS,CAAC,CAAA;AACpE,EAAA,OAAO,kBAAkB,SAAA,EAAW,KAAA,CAAM,IAAA,IAAQ,WAAA,CAAY,SAAS,QAAQ,CAAA;AACjF;AAEA,SAAS,kBAAkB,QAAA,EAA0B;AAEnD,EAAA,IAAI,aAAa,QAAA,CAAS,UAAA,CAAW,GAAG,CAAA,GAAI,QAAA,GAAW,IAAI,QAAQ,CAAA,CAAA;AAEnE,EAAA,IAAI,WAAW,MAAA,GAAS,CAAA,IAAK,UAAA,CAAW,QAAA,CAAS,GAAG,CAAA,EAAG;AACrD,IAAA,UAAA,GAAa,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,UAAA;AACT;;;;"}
1
+ {"version":3,"file":"hydratedRouter.js","sources":["../../../src/client/hydratedRouter.ts"],"sourcesContent":["import { getAbsoluteUrl, startBrowserTracingNavigationSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport {\n debug,\n getActiveSpan,\n getClient,\n getRootSpan,\n GLOBAL_OBJ,\n isThenable,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { DataRouter } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isClientInstrumentationApiUsed } from './createClientInstrumentation';\nimport {\n finalizeNavigationSpanFromRouterState,\n getParameterizedRoute,\n normalizePathname,\n resolveNavigateAbsoluteUrl,\n resolveNavigateArg,\n} from './utils';\nimport { URL_PATH, URL_TEMPLATE } from '@sentry/conventions/attributes';\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\nconst MAX_RETRIES = 40; // 2 seconds at 50ms interval\n\n/**\n * Instruments the React Router Data Router for pageloads and navigation.\n *\n * This function waits for the router to be available after hydration, then:\n * 1. Updates the pageload transaction with parameterized route info\n * 2. Patches router.navigate() to create navigation transactions\n * 3. Subscribes to router state changes to update navigation transactions with parameterized routes\n */\nexport function instrumentHydratedRouter(): void {\n function trySubscribe(): boolean {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n\n if (router) {\n // The first time we hit the router, we try to update the pageload transaction\n const pageloadSpan = getActiveRootSpan();\n\n if (pageloadSpan) {\n const pageloadName = spanToJSON(pageloadSpan).description;\n const parameterizePageloadRoute = getParameterizedRoute(router.state);\n if (\n pageloadName &&\n // this event is for the currently active pageload\n normalizePathname(router.state.location.pathname) === normalizePathname(pageloadName)\n ) {\n pageloadSpan.updateName(parameterizePageloadRoute);\n pageloadSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react_router',\n [URL_TEMPLATE]: parameterizePageloadRoute,\n });\n }\n }\n\n // Patching navigate for creating accurate navigation transactions\n if (typeof router.navigate === 'function') {\n const originalNav = router.navigate.bind(router);\n router.navigate = function sentryPatchedNavigate(...args) {\n // Skip if instrumentation API is enabled (it handles navigation spans itself)\n if (!isClientInstrumentationApiUsed()) {\n const target = args[0];\n\n if (typeof target === 'number') {\n // navigate(0) triggers a reload, not a route change — skip span creation\n if (target !== 0) {\n const currentPathname = WINDOW.location?.pathname || '/';\n const navigationSpan = maybeCreateNavigationTransaction(\n currentPathname,\n getAbsoluteUrl(currentPathname),\n 'url',\n );\n\n const result = originalNav(...args);\n\n // Numeric navigations (`navigate(-1)`/`navigate(1)`) don't carry a destination\n // path, so we can only resolve the real URL/route once the router has settled.\n if (navigationSpan) {\n // Finalize from the (updated) router state after navigation completes, in both\n // the resolve and reject paths, so a rejected navigation still ends up with the\n // correct URL attributes instead of the placeholder start pathname.\n if (isThenable(result)) {\n result.then(\n () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state),\n () => finalizeNavigationSpanFromRouterState(navigationSpan, router.state),\n );\n } else {\n finalizeNavigationSpanFromRouterState(navigationSpan, router.state);\n }\n }\n\n return result;\n }\n } else {\n maybeCreateNavigationTransaction(\n resolveNavigateArg(target) || '<unknown route>',\n resolveNavigateAbsoluteUrl(target),\n 'url',\n );\n }\n }\n return originalNav(...args);\n };\n }\n\n // Subscribe to router state changes to update navigation transactions (and any pageload\n // whose route info only became available after `trySubscribe`, e.g. lazy routes) with the\n // parameterized route.\n router.subscribe(newState => {\n const rootSpan = getActiveRootSpan();\n\n if (!rootSpan) {\n return;\n }\n\n const rootSpanJson = spanToJSON(rootSpan);\n\n // When the instrumentation API is active, navigation roots are parameterized\n // by the native route hooks\n if (\n rootSpanJson.op === 'navigation' &&\n isClientInstrumentationApiUsed() &&\n rootSpanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'route'\n ) {\n return;\n }\n\n const rootSpanName = rootSpanJson.description;\n const parameterizedRoute = getParameterizedRoute(newState);\n const spanPathname = rootSpanJson.data?.[URL_PATH] as string | undefined;\n const destinationPathname = normalizePathname(newState.location.pathname);\n\n if (\n rootSpanName &&\n newState.navigation.state === 'idle' && // navigation has completed\n // this event is for the currently active root span\n (destinationPathname === normalizePathname(rootSpanName) ||\n (spanPathname && destinationPathname === normalizePathname(spanPathname)))\n ) {\n rootSpan.updateName(parameterizedRoute);\n rootSpan.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: parameterizedRoute });\n }\n });\n return true;\n }\n return false;\n }\n\n // Wait until the router is available (since the SDK loads before hydration)\n if (!trySubscribe()) {\n let retryCount = 0;\n // Retry until the router is available or max retries reached\n const interval = setInterval(() => {\n if (trySubscribe() || retryCount >= MAX_RETRIES) {\n if (retryCount >= MAX_RETRIES) {\n DEBUG_BUILD && debug.warn('Unable to instrument React Router: router not found after hydration.');\n }\n clearInterval(interval);\n }\n retryCount++;\n }, 50);\n }\n}\n\nfunction maybeCreateNavigationTransaction(name: string, url: string, source: 'url' | 'route'): Span | undefined {\n const client = getClient();\n\n if (!client) {\n return undefined;\n }\n\n return startBrowserTracingNavigationSpan(\n client,\n {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react_router',\n ...(source === 'route' ? { [URL_TEMPLATE]: name } : {}),\n },\n },\n { url },\n );\n}\n\nfunction getActiveRootSpan(): Span | undefined {\n const activeSpan = getActiveSpan();\n if (!activeSpan) {\n return undefined;\n }\n\n const rootSpan = getRootSpan(activeSpan);\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":[],"mappings":";;;;;;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,EAAA,OAAO,iCAAA;AAAA,IACL,MAAA;AAAA,IACA;AAAA,MACE,IAAA;AAAA,MACA,UAAA,EAAY;AAAA,QACV,CAAC,gCAAgC,GAAG,MAAA;AAAA,QACpC,CAAC,4BAA4B,GAAG,YAAA;AAAA,QAChC,CAAC,gCAAgC,GAAG,8BAAA;AAAA,QACpC,GAAoD;AAAC;AACvD,KACF;AAAA,IACA,EAAE,GAAA;AAAI,GACR;AACF;AAEA,SAAS,iBAAA,GAAsC;AAC7C,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,QAAA,GAAW,YAAY,UAAU,CAAA;AAEvC,EAAA,MAAM,EAAA,GAAK,UAAA,CAAW,QAAQ,CAAA,CAAE,EAAA;AAGhC,EAAA,OAAO,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,GAAa,QAAA,GAAW,MAAA;AAC/D;;;;"}
@@ -1,5 +1,9 @@
1
- import { GLOBAL_OBJ } from '@sentry/core';
1
+ import { getAbsoluteUrl } from '@sentry/browser';
2
+ import { GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
3
+ import { URL_FULL, URL_PATH, URL_TEMPLATE } from '@sentry/conventions/attributes';
2
4
 
5
+ const WINDOW = GLOBAL_OBJ;
6
+ const GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ;
3
7
  function resolveNavigateArg(target) {
4
8
  if (typeof target !== "object" || target === null) {
5
9
  return String(target);
@@ -8,8 +12,82 @@ function resolveNavigateArg(target) {
8
12
  if (typeof pathname === "string") {
9
13
  return pathname || "/";
10
14
  }
11
- return GLOBAL_OBJ.location?.pathname || "/";
15
+ return WINDOW.location?.pathname || "/";
16
+ }
17
+ function resolveNavigateUrl(target) {
18
+ if (typeof target !== "object" || target === null) {
19
+ return String(target);
20
+ }
21
+ const { pathname, search, hash } = target;
22
+ const path = typeof pathname === "string" && pathname !== "" ? pathname : WINDOW.location?.pathname || "/";
23
+ return `${path}${typeof search === "string" ? search : ""}${typeof hash === "string" ? hash : ""}`;
24
+ }
25
+ function getNavigateBaseUrl(currentUrl) {
26
+ const origin = WINDOW.location?.origin || "http://localhost";
27
+ let pathname = WINDOW.location?.pathname;
28
+ if (!pathname && currentUrl) {
29
+ try {
30
+ pathname = new URL(currentUrl, origin).pathname;
31
+ } catch {
32
+ pathname = currentUrl.startsWith("/") ? currentUrl : `/${currentUrl}`;
33
+ }
34
+ }
35
+ pathname = pathname || "/";
36
+ const directory = pathname.endsWith("/") ? pathname : `${pathname}/`;
37
+ return `${origin}${directory}`;
38
+ }
39
+ function resolveNavigateAbsoluteUrl(target, currentUrl) {
40
+ const destination = resolveNavigateUrl(target);
41
+ try {
42
+ const resolved = new URL(destination, getNavigateBaseUrl(currentUrl));
43
+ return getAbsoluteUrl(`${resolved.pathname}${resolved.search}${resolved.hash}`);
44
+ } catch {
45
+ return getAbsoluteUrl(destination);
46
+ }
47
+ }
48
+ function updateNavigationSpanUrlFromLocation(span) {
49
+ if (!WINDOW.location) {
50
+ return;
51
+ }
52
+ const { pathname, search = "", hash = "" } = WINDOW.location;
53
+ const destinationUrl = getAbsoluteUrl(`${pathname}${search}${hash}`);
54
+ span.updateName(pathname);
55
+ span.setAttributes({
56
+ [URL_PATH]: pathname,
57
+ [URL_FULL]: destinationUrl
58
+ });
59
+ }
60
+ function normalizePathname(pathname) {
61
+ let normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
62
+ if (normalized.length > 1 && normalized.endsWith("/")) {
63
+ normalized = normalized.slice(0, -1);
64
+ }
65
+ return normalized;
66
+ }
67
+ function getParameterizedRoute(routerState) {
68
+ const lastMatch = routerState.matches[routerState.matches.length - 1];
69
+ return normalizePathname(lastMatch?.route.path || routerState.location.pathname);
70
+ }
71
+ function finalizeNavigationSpanFromRouterState(span, routerState) {
72
+ updateNavigationSpanUrlFromLocation(span);
73
+ if (!WINDOW.location) {
74
+ return;
75
+ }
76
+ const { pathname } = WINDOW.location;
77
+ if (routerState.navigation?.state === "idle" && normalizePathname(routerState.location.pathname) === normalizePathname(pathname)) {
78
+ const parameterizedRoute = getParameterizedRoute(routerState);
79
+ span.updateName(parameterizedRoute);
80
+ span.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", [URL_TEMPLATE]: parameterizedRoute });
81
+ }
82
+ }
83
+ function finalizeNavigationSpanFromHydratedRouter(span) {
84
+ const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;
85
+ if (router) {
86
+ finalizeNavigationSpanFromRouterState(span, router.state);
87
+ } else {
88
+ updateNavigationSpanUrlFromLocation(span);
89
+ }
12
90
  }
13
91
 
14
- export { resolveNavigateArg };
92
+ export { finalizeNavigationSpanFromHydratedRouter, finalizeNavigationSpanFromRouterState, getParameterizedRoute, normalizePathname, resolveNavigateAbsoluteUrl, resolveNavigateArg, resolveNavigateUrl, updateNavigationSpanUrlFromLocation };
15
93
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/client/utils.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/**\n * Resolves a navigate argument to a pathname string.\n *\n * React Router's navigate() accepts a string, number, or a To object ({ pathname, search, hash }).\n * All fields in the To object are optional (Partial<Path>), so we need to detect object args\n * to avoid \"[object Object]\" transaction names.\n */\nexport function resolveNavigateArg(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n // Object `to` with pathname\n const pathname = (target as Record<string, unknown>).pathname;\n if (typeof pathname === 'string') {\n return pathname || '/';\n }\n\n // Object `to` without pathname - navigation stays on current path\n return (GLOBAL_OBJ as typeof GLOBAL_OBJ & Window).location?.pathname || '/';\n}\n"],"names":[],"mappings":";;AASO,SAAS,mBAAmB,MAAA,EAAyB;AAC1D,EAAA,IAAI,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,KAAW,IAAA,EAAM;AAEjD,IAAA,OAAO,OAAO,MAAM,CAAA;AAAA,EACtB;AAGA,EAAA,MAAM,WAAY,MAAA,CAAmC,QAAA;AACrD,EAAA,IAAI,OAAO,aAAa,QAAA,EAAU;AAChC,IAAA,OAAO,QAAA,IAAY,GAAA;AAAA,EACrB;AAGA,EAAA,OAAQ,UAAA,CAA0C,UAAU,QAAA,IAAY,GAAA;AAC1E;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/client/utils.ts"],"sourcesContent":["import { getAbsoluteUrl } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport { URL_FULL, URL_PATH, URL_TEMPLATE } from '@sentry/conventions/attributes';\nimport type { DataRouter, RouterState } from 'react-router';\n\nconst WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;\n\nconst GLOBAL_OBJ_WITH_DATA_ROUTER = GLOBAL_OBJ as typeof GLOBAL_OBJ & {\n __reactRouterDataRouter?: DataRouter;\n};\n\n/**\n * Resolves a navigate argument to a pathname string.\n *\n * React Router's navigate() accepts a string, number, or a To object ({ pathname, search, hash }).\n * All fields in the To object are optional (Partial<Path>), so we need to detect object args\n * to avoid \"[object Object]\" transaction names.\n */\nexport function resolveNavigateArg(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n // Object `to` with pathname\n const pathname = (target as Record<string, unknown>).pathname;\n if (typeof pathname === 'string') {\n return pathname || '/';\n }\n\n // Object `to` without pathname - navigation stays on current path\n return WINDOW.location?.pathname || '/';\n}\n\n/**\n * Resolves a navigate argument to the full destination path, preserving `search`/`hash` from a\n * To object. Unlike `resolveNavigateArg` (used for span/route naming, which should stay a bare\n * path), this is used to derive `url.full`/`url.path`, which should reflect the actual\n * destination the user is navigating to, including any query string.\n */\nexport function resolveNavigateUrl(target: unknown): string {\n if (typeof target !== 'object' || target === null) {\n // string or number\n return String(target);\n }\n\n const { pathname, search, hash } = target as Record<string, unknown>;\n const path = typeof pathname === 'string' && pathname !== '' ? pathname : WINDOW.location?.pathname || '/';\n\n return `${path}${typeof search === 'string' ? search : ''}${typeof hash === 'string' ? hash : ''}`;\n}\n\nfunction getNavigateBaseUrl(currentUrl?: string): string {\n const origin = WINDOW.location?.origin || 'http://localhost';\n\n // Prefer the live pathname, but fall back to the hook-provided `currentUrl` (which may be a full\n // URL or a bare path) when `location` is unavailable (e.g. SSR/non-browser environments).\n let pathname = WINDOW.location?.pathname;\n if (!pathname && currentUrl) {\n try {\n pathname = new URL(currentUrl, origin).pathname;\n } catch {\n pathname = currentUrl.startsWith('/') ? currentUrl : `/${currentUrl}`;\n }\n }\n pathname = pathname || '/';\n\n // React Router resolves relative navigate targets against the current path treated as a\n // *directory* (it appends segments), whereas the WHATWG `URL` parser treats the last path\n // segment as a file and drops it. Enforce a trailing slash so relative resolution matches\n // React Router, e.g. `navigate('ssr')` from `/performance` -> `/performance/ssr` (not `/ssr`).\n const directory = pathname.endsWith('/') ? pathname : `${pathname}/`;\n\n return `${origin}${directory}`;\n}\n\n/**\n * Resolves a navigate argument to an absolute URL for `url.full`/`url.path`, correctly handling\n * relative targets (no leading slash) by resolving them against the current URL instead of the\n * document origin alone.\n */\nexport function resolveNavigateAbsoluteUrl(target: unknown, currentUrl?: string): string {\n const destination = resolveNavigateUrl(target);\n\n try {\n const resolved = new URL(destination, getNavigateBaseUrl(currentUrl));\n return getAbsoluteUrl(`${resolved.pathname}${resolved.search}${resolved.hash}`);\n } catch {\n return getAbsoluteUrl(destination);\n }\n}\n\n/**\n * Updates a navigation span's name and `url.path`/`url.full` from the current `location`.\n */\nexport function updateNavigationSpanUrlFromLocation(span: Span): void {\n if (!WINDOW.location) {\n return;\n }\n\n const { pathname, search = '', hash = '' } = WINDOW.location;\n const destinationUrl = getAbsoluteUrl(`${pathname}${search}${hash}`);\n\n span.updateName(pathname);\n span.setAttributes({\n [URL_PATH]: pathname,\n [URL_FULL]: destinationUrl,\n });\n}\n\nexport function normalizePathname(pathname: string): string {\n let normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;\n if (normalized.length > 1 && normalized.endsWith('/')) {\n normalized = normalized.slice(0, -1);\n }\n return normalized;\n}\n\nexport function getParameterizedRoute(routerState: RouterState): string {\n const lastMatch = routerState.matches[routerState.matches.length - 1];\n return normalizePathname(lastMatch?.route.path || routerState.location.pathname);\n}\n\n/**\n * Updates a navigation span's URL attributes and parameterizes its name from the router state.\n * Used after numeric navigations (`navigate(-1)` / `navigate(1)`) where route hooks may not\n * supply a pattern (e.g. index routes).\n *\n * `url.path` reflects raw `location.pathname` (may include a trailing slash when the server\n * redirects index routes), while `url.template` is normalized without trailing slashes.\n */\nexport function finalizeNavigationSpanFromRouterState(span: Span, routerState: RouterState): void {\n updateNavigationSpanUrlFromLocation(span);\n\n if (!WINDOW.location) {\n return;\n }\n\n const { pathname } = WINDOW.location;\n\n if (\n routerState.navigation?.state === 'idle' &&\n normalizePathname(routerState.location.pathname) === normalizePathname(pathname)\n ) {\n const parameterizedRoute = getParameterizedRoute(routerState);\n span.updateName(parameterizedRoute);\n span.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [URL_TEMPLATE]: parameterizedRoute });\n }\n}\n\n/**\n * Finalizes a navigation span after numeric navigation using the hydrated data router when\n * available, otherwise falls back to URL attributes from `location` alone.\n */\nexport function finalizeNavigationSpanFromHydratedRouter(span: Span): void {\n const router = GLOBAL_OBJ_WITH_DATA_ROUTER.__reactRouterDataRouter;\n if (router) {\n finalizeNavigationSpanFromRouterState(span, router.state);\n } else {\n updateNavigationSpanUrlFromLocation(span);\n }\n}\n"],"names":[],"mappings":";;;;AAMA,MAAM,MAAA,GAAS,UAAA;AAEf,MAAM,2BAAA,GAA8B,UAAA;AAW7B,SAAS,mBAAmB,MAAA,EAAyB;AAC1D,EAAA,IAA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,EAAM,OAAO,KAAK,CAAA;AAAA,EAC1D,CAAA,MAAO;AACL,IAAA,mCAAA,CAAoC,IAAI,CAAA;AAAA,EAC1C;AACF;;;;"}
@@ -1 +1 @@
1
- {"type":"module","version":"10.64.0"}
1
+ {"type":"module","version":"10.66.0"}
@@ -1 +1 @@
1
- {"version":3,"file":"createClientInstrumentation.d.ts","sourceRoot":"","sources":["../../../src/client/createClientInstrumentation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,qBAAqB,EAA6C,MAAM,iBAAiB,CAAC;AAyBxG;;GAEG;AACH,MAAM,WAAW,wCAAwC;IACvD;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,GAAE,wCAA6C,GACrD,qBAAqB,CAsRvB;AA0BD;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAExD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C"}
1
+ {"version":3,"file":"createClientInstrumentation.d.ts","sourceRoot":"","sources":["../../../src/client/createClientInstrumentation.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,qBAAqB,EAA6C,MAAM,iBAAiB,CAAC;AA+BxG;;GAEG;AACH,MAAM,WAAW,wCAAwC;IACvD;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,GAAE,wCAA6C,GACrD,qBAAqB,CAkSvB;AA0BD;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAExD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"hydratedRouter.d.ts","sourceRoot":"","sources":["../../../src/client/hydratedRouter.ts"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CA0F/C"}
1
+ {"version":3,"file":"hydratedRouter.d.ts","sourceRoot":"","sources":["../../../src/client/hydratedRouter.ts"],"names":[],"mappings":"AAkCA;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAoI/C"}
@@ -1,3 +1,5 @@
1
+ import type { Span } from '@sentry/core';
2
+ import type { RouterState } from 'react-router';
1
3
  /**
2
4
  * Resolves a navigate argument to a pathname string.
3
5
  *
@@ -6,4 +8,37 @@
6
8
  * to avoid "[object Object]" transaction names.
7
9
  */
8
10
  export declare function resolveNavigateArg(target: unknown): string;
11
+ /**
12
+ * Resolves a navigate argument to the full destination path, preserving `search`/`hash` from a
13
+ * To object. Unlike `resolveNavigateArg` (used for span/route naming, which should stay a bare
14
+ * path), this is used to derive `url.full`/`url.path`, which should reflect the actual
15
+ * destination the user is navigating to, including any query string.
16
+ */
17
+ export declare function resolveNavigateUrl(target: unknown): string;
18
+ /**
19
+ * Resolves a navigate argument to an absolute URL for `url.full`/`url.path`, correctly handling
20
+ * relative targets (no leading slash) by resolving them against the current URL instead of the
21
+ * document origin alone.
22
+ */
23
+ export declare function resolveNavigateAbsoluteUrl(target: unknown, currentUrl?: string): string;
24
+ /**
25
+ * Updates a navigation span's name and `url.path`/`url.full` from the current `location`.
26
+ */
27
+ export declare function updateNavigationSpanUrlFromLocation(span: Span): void;
28
+ export declare function normalizePathname(pathname: string): string;
29
+ export declare function getParameterizedRoute(routerState: RouterState): string;
30
+ /**
31
+ * Updates a navigation span's URL attributes and parameterizes its name from the router state.
32
+ * Used after numeric navigations (`navigate(-1)` / `navigate(1)`) where route hooks may not
33
+ * supply a pattern (e.g. index routes).
34
+ *
35
+ * `url.path` reflects raw `location.pathname` (may include a trailing slash when the server
36
+ * redirects index routes), while `url.template` is normalized without trailing slashes.
37
+ */
38
+ export declare function finalizeNavigationSpanFromRouterState(span: Span, routerState: RouterState): void;
39
+ /**
40
+ * Finalizes a navigation span after numeric navigation using the hydrated data router when
41
+ * available, otherwise falls back to URL attributes from `location` alone.
42
+ */
43
+ export declare function finalizeNavigationSpanFromHydratedRouter(span: Span): void;
9
44
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/client/utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAc1D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/client/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,cAAc,CAAC;AAQ5D;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAc1D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAU1D;AA0BD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CASvF;AAED;;GAEG;AACH,wBAAgB,mCAAmC,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAapE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAGtE;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAiBhG;AAED;;;GAGG;AACH,wBAAgB,wCAAwC,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAOzE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/react-router",
3
- "version": "10.64.0",
3
+ "version": "10.66.0",
4
4
  "description": "Official Sentry SDK for React Router (Framework)",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/react-router",
@@ -47,12 +47,12 @@
47
47
  "dependencies": {
48
48
  "@opentelemetry/api": "^1.9.1",
49
49
  "@opentelemetry/instrumentation": "^0.220.0",
50
- "@sentry/browser": "10.64.0",
50
+ "@sentry/browser": "10.66.0",
51
51
  "@sentry/cli": "^2.58.6",
52
- "@sentry/conventions": "^0.15.1",
53
- "@sentry/core": "10.64.0",
54
- "@sentry/node": "10.64.0",
55
- "@sentry/react": "10.64.0",
52
+ "@sentry/conventions": "^0.16.0",
53
+ "@sentry/core": "10.66.0",
54
+ "@sentry/node": "10.66.0",
55
+ "@sentry/react": "10.66.0",
56
56
  "@sentry/vite-plugin": "^5.3.0",
57
57
  "glob": "^13.0.6"
58
58
  },