Skip to content

Commit 1c56763

Browse files
feat(tracing): Add section about beforeNavigation (#1777)
Co-authored-by: Tien "Mimi" Nguyen <[email protected]>
1 parent da2af2b commit 1c56763

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/collections/_documentation/performance/distributed-tracing.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,33 @@ The default value of `tracingOrigins` is `['localhost', /^\//]`. The JavaScript
465465

466466
*NOTE:* You need to make sure your web server CORS is configured to allow the `sentry-trace` header. The configuration might look like `"Access-Control-Allow-Headers: sentry-trace"`, but this depends a lot on your set up. If you do not whitelist the `sentry-trace` header, the request might be blocked.
467467

468+
*beforeNavigation Option*
469+
470+
{% version_added 5.18.0 %}
471+
472+
For `pageload` and `navigation` transactions, the `Tracing` integration uses the browser's `window.location` API to generate a transaction name. To customize the name of the `pageload` and `navigation` transactions, you can supply a `beforeNavigation` option to the `Tracing` integration. This option allows you to pass in a function that takes in the location at the time of navigation and returns a new transaction name.
473+
474+
`beforeNavigation` is useful if you would like to leverage the routes from a custom routing library like `React Router` or if you want to reduce the cardinality of particular transactions.
475+
476+
```javascript
477+
import * as Sentry from '@sentry/browser';
478+
import { Integrations as ApmIntegrations } from '@sentry/apm';
479+
480+
Sentry.init({
481+
dsn: '___PUBLIC_DSN___',
482+
integrations: [
483+
new ApmIntegrations.Tracing({
484+
beforeNavigate: (location) => {
485+
// The normalizeTransactionName function uses the given URL to
486+
// generate a new transaction name.
487+
return normalizeTransactionName(location.href);
488+
},
489+
}),
490+
],
491+
tracesSampleRate: 0.25,
492+
});
493+
```
494+
468495
#### Manual Instrumentation
469496

470497
To manually instrument certain regions of your code, you can create a transaction to capture them.

0 commit comments

Comments
 (0)