-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add docs for custom browser tracing routing instrumentation (#9113
) --------- Co-authored-by: Liza Mock <[email protected]>
- Loading branch information
Showing
4 changed files
with
50 additions
and
38 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
includes/performance/browser-custom-routing-instrumentation.mdx
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...rm-includes/performance/automatic-instrumentation-custom-routing/javascript.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters