From d12da8896b5c65f04eed4da3100ac1fe2090e7ac Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 22 Jun 2020 08:36:31 -0400 Subject: [PATCH 1/5] feat(tracing): Add beforeNavigate option --- packages/apm/src/integrations/tracing.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index fb16a96b84bc..57b432053333 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -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 */ @@ -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, @@ -224,7 +236,7 @@ export class Tracing implements Integration { if (global.location && global.location.href && Tracing.options && Tracing.options.startTransactionOnPageLoad) { // Use `${global.location.href}` as transaction name Tracing.startIdleTransaction({ - name: global.location.href, + name: Tracing.options.beforeNavigate(window.location), op: 'pageload', }); } @@ -997,7 +1009,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', }); } From 9f06a230352c9230ae97518e0331c78d1094c811 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 22 Jun 2020 08:38:31 -0400 Subject: [PATCH 2/5] docs: Edit CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7535e6ca4ea0..dc69850526eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `setNavigationTransactionName` option +- [tracing] ref: Create navigation transactions using `window.location.pathname` instead of `window.location.href` ## 5.17.0 From 04f2672fb84dba39a32a148986f3fbc90a2d9a9e Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 22 Jun 2020 08:46:41 -0400 Subject: [PATCH 3/5] fix: Remove reference to location.href --- packages/apm/src/integrations/tracing.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 57b432053333..4f9793f33ac5 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -233,8 +233,7 @@ 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: Tracing.options.beforeNavigate(window.location), op: 'pageload', From 1d25bf2fa682a7ea772bfa2dcaa29b554ea9824a Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 22 Jun 2020 08:50:13 -0400 Subject: [PATCH 4/5] docs: Add PR number --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc69850526eb..a78bbf50682f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +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 `setNavigationTransactionName` option -- [tracing] ref: Create navigation transactions using `window.location.pathname` instead of `window.location.href` +- [tracing] feat: Add `setNavigationTransactionName` option (#2691) +- [tracing] ref: Create navigation transactions using `window.location.pathname` instead of `window.location.href` (#2691) ## 5.17.0 From d8d45409da8632bcb8093f42ca59c605ba92d1b9 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 22 Jun 2020 09:03:34 -0400 Subject: [PATCH 5/5] docs: update CHANGELOG to use correct option --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a78bbf50682f..5f55e91769b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - [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 `setNavigationTransactionName` option (#2691) +- [tracing] feat: Add `beforeNavigate` option (#2691) - [tracing] ref: Create navigation transactions using `window.location.pathname` instead of `window.location.href` (#2691) ## 5.17.0