Skip to content
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

feat(tracing): Add beforeNavigate option #2691

Merged
merged 5 commits into from Jun 22, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@
- [react] ref: Refactor Profiler to account for update and render (#2677)
- [apm] feat: Add ability to get span from activity using `getActivitySpan` (#2677)
- [apm] fix: Check if `performance.mark` exists before calling it (#2680)
- [tracing] feat: Add `beforeNavigate` option (#2691)
- [tracing] ref: Create navigation transactions using `window.location.pathname` instead of `window.location.href` (#2691)

## 5.17.0

Expand Down
19 changes: 15 additions & 4 deletions packages/apm/src/integrations/tracing.ts
Expand Up @@ -107,6 +107,15 @@ export interface TracingOptions {
writeAsBreadcrumbs: boolean;
spanDebugTimingInfo: boolean;
};

/**
* beforeNavigate is called before a pageload/navigation transaction is created and allows for users
* to set a custom navigation transaction name based on the current `window.location`. Defaults to returning
* `window.location.pathname`.
*
* @param location the current location before navigation span is created
*/
beforeNavigate(location: Location): string;
}

/** JSDoc */
Expand Down Expand Up @@ -177,6 +186,9 @@ export class Tracing implements Integration {
Tracing._trackLCP();
}
const defaults = {
beforeNavigate(location: Location): string {
return location.pathname;
},
debug: {
spanDebugTimingInfo: false,
writeAsBreadcrumbs: false,
Expand Down Expand Up @@ -221,10 +233,9 @@ export class Tracing implements Integration {
}

// Starting pageload transaction
if (global.location && global.location.href && Tracing.options && Tracing.options.startTransactionOnPageLoad) {
// Use `${global.location.href}` as transaction name
if (global.location && Tracing.options && Tracing.options.startTransactionOnPageLoad) {
Tracing.startIdleTransaction({
name: global.location.href,
name: Tracing.options.beforeNavigate(window.location),
op: 'pageload',
});
}
Expand Down Expand Up @@ -997,7 +1008,7 @@ function historyCallback(_: { [key: string]: any }): void {
if (Tracing.options.startTransactionOnLocationChange && global && global.location) {
Tracing.finishIdleTransaction(timestampWithMs());
Tracing.startIdleTransaction({
name: global.location.href,
name: Tracing.options.beforeNavigate(window.location),
op: 'navigation',
});
}
Expand Down