diff --git a/includes/performance/browser-custom-routing-instrumentation.mdx b/includes/performance/browser-custom-routing-instrumentation.mdx deleted file mode 100644 index 4c1b309437edf..0000000000000 --- a/includes/performance/browser-custom-routing-instrumentation.mdx +++ /dev/null @@ -1,36 +0,0 @@ -If you use a custom client-side router, you can define your own custom router instrumentation. - -```TypeScript -export function customRoutingInstrumentation( - customStartTransaction: (context) => T | undefined, - startTransactionOnPageLoad: boolean = true, - startTransactionOnLocationChange: boolean = true, -): void { - // Track initial pageload - if (startTransactionOnPageLoad) { - customStartTransaction({ name: getCustomRouteName() }); - } - - // Track route changes - if (startTransactionOnLocationChange) { - // MyCustomRouter is a custom router that you define, you can use any router you want - MyCustomRouter.on('routeChange', (routeName) => { - customStartTransaction({ name: routeName }); - }); - } -} - -// Then later when you initialize Sentry - -Sentry.init({ - dsn: '__PUBLIC_DSN__', - tracesSampleRate: 1.0, - integrations: [ - new Sentry.BrowserTracing({ - routingInstrumentation: customRoutingInstrumentation, - }), - ], -}); -``` - -An example implementation for custom `routingInstrumentation` can be found in this example for [Inertia.js](https://github.com/getsentry/sentry-javascript/discussions/8528). diff --git a/platform-includes/performance/automatic-instrumentation-custom-routing/javascript.mdx b/platform-includes/performance/automatic-instrumentation-custom-routing/javascript.mdx new file mode 100644 index 0000000000000..0eb3bfa0f410a --- /dev/null +++ b/platform-includes/performance/automatic-instrumentation-custom-routing/javascript.mdx @@ -0,0 +1,46 @@ +### Custom Routing + +By default, the `browserTracingIntegration()` will create a `pageload` span for when the page is initially loaded, as well as a `navigation` span for whenever the URL changes afterwards. + +To make sure that spans are created correctly for a custom routing setup, you'll need to opt out of the default span creation by setting `instrumentNavigation: false` and `instrumentPageLoad: false` in the `browserTracingIntegration()` options. You can then manually create spans like this: + +```javascript +Sentry.init({ + integrations: [ + Sentry.browserTracingIntegration({ + // disable automatic span creation + instrumentNavigation: false, + instrumentPageLoad: false, + }), + ], +}); + +// We start the pageload span as early as possible! +let pageLoadSpan = Sentry.startBrowserTracingPageLoadSpan({ + name: window.location.pathname + attributes: { + [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url", + }, +}); + +// Somewhere, instrument your router like this: +myRouter.on("routeChange", (route) => { + const client = Sentry.getClient(); + + // Make sure that the pageload span uses the route name + // After that, each route change should trigger a navigation span (which will automatically finish the previous one) + if (pageLoadSpan) { + pageloadSpan.updateName(route.name); + pageloadSpan.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route"); + pageLoadSpan = undefined; + } else { + Sentry.startBrowserTracingNavigationSpan(client, { + op: "navigation", + name: route.name, // or what the name of the span should be + attributes: { + [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route", + }, + }); + } +}); +``` diff --git a/platform-includes/performance/enable-automatic-instrumentation/javascript.mdx b/platform-includes/performance/enable-automatic-instrumentation/javascript.mdx index 6181b5fd0f9d2..05f4c33b9652e 100644 --- a/platform-includes/performance/enable-automatic-instrumentation/javascript.mdx +++ b/platform-includes/performance/enable-automatic-instrumentation/javascript.mdx @@ -19,3 +19,5 @@ Sentry.init({ tracesSampleRate: 1.0, }); ``` + + \ No newline at end of file diff --git a/platform-includes/performance/enable-automatic-instrumentation/javascript.react.mdx b/platform-includes/performance/enable-automatic-instrumentation/javascript.react.mdx index e40063b6ad0fc..d60031cfb7abf 100644 --- a/platform-includes/performance/enable-automatic-instrumentation/javascript.react.mdx +++ b/platform-includes/performance/enable-automatic-instrumentation/javascript.react.mdx @@ -22,8 +22,6 @@ Sentry.init({ // * reactRouterV4BrowserTracingInstrumentation // * reactRouterV6BrowserTracingInstrumentation // or just browserTracingIntegration - routingInstrumentation: Sentry.reactRouterV5Instrumentation(history), - // ... other options }), ], @@ -34,3 +32,5 @@ Sentry.init({ ``` Now you should be generating `pageload`/`navigation` transactions from the `BrowserTracing` integration, using Sentry's [`react-router` instrumentation](/platforms/javascript/guides/react/configuration/integrations/react-router/). + + \ No newline at end of file