-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add docs for custom browser tracing routing instrumentation #9113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) => { | ||
| 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 |
|---|---|---|
|
|
@@ -19,3 +19,5 @@ Sentry.init({ | |
| tracesSampleRate: 1.0, | ||
| }); | ||
| ``` | ||
|
|
||
| <PlatformContent includePath="performance/automatic-instrumentation-custom-routing" /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!