Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions includes/performance/browser-custom-routing-instrumentation.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a note about setting correct route name for pageload as well, we want to avoid un-paramaterized transactions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is mostly about updating the pageload span, right? 🤔 or should we document how to emit a pageload span?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah updating the pageload span, I think most frameworks will be fine with emitting pageload as soon as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a PR: getsentry/sentry-javascript#10633 to make this easier, as documenting this showed that there is def. room for improvement there!

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",
},
});
}
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ Sentry.init({
tracesSampleRate: 1.0,
});
```

<PlatformContent includePath="performance/automatic-instrumentation-custom-routing" />
Copy link
Member

@Lms24 Lms24 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: should this documentation live under "Automatic Instrumentation"? Isn't this rather fitting for "Custom Instrumentation"?

I guess there's a case for both, given we're mentioning browserTracingIntegration directly above but maybe it's enough to link to custom from the "Autmatic Instrumentation" page

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, IMHO I'd generally restructure this a bit in a follow up - we should rethink this with a bit of time! Currently that's basically the "browser tracing" page, in reality, even though the name is not necessarily clear on that.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Sentry.init({
// * reactRouterV4BrowserTracingInstrumentation
// * reactRouterV6BrowserTracingInstrumentation
// or just browserTracingIntegration
routingInstrumentation: Sentry.reactRouterV5Instrumentation(history),
// ... other options
}),
],

Expand All @@ -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/).

<PlatformContent includePath="performance/automatic-instrumentation-custom-routing" />