11import { Primitive , Transaction , TransactionContext } from '@sentry/types' ;
2- import { fill , getGlobalObject } from '@sentry/utils' ;
2+ import { fill , getGlobalObject , stripUrlQueryAndFragment } from '@sentry/utils' ;
33import { default as Router } from 'next/router' ;
44
55const global = getGlobalObject < Window > ( ) ;
@@ -10,8 +10,6 @@ const DEFAULT_TAGS = Object.freeze({
1010 'routing.instrumentation' : 'next-router' ,
1111} ) ;
1212
13- const QUERY_PARAM_REGEX = / \? ( .* ) / ;
14-
1513let activeTransaction : Transaction | undefined = undefined ;
1614let prevTransactionName : string | undefined = undefined ;
1715let startTransaction : StartTransactionCb | undefined = undefined ;
@@ -35,7 +33,7 @@ export function nextRouterInstrumentation(
3533 // route name. Setting the transaction name after the transaction is started could lead
3634 // to possible race conditions with the router, so this approach was taken.
3735 if ( startTransactionOnPageLoad ) {
38- prevTransactionName = Router . route !== null ? removeQueryParams ( Router . route ) : global . location . pathname ;
36+ prevTransactionName = Router . route !== null ? stripUrlQueryAndFragment ( Router . route ) : global . location . pathname ;
3937 activeTransaction = startTransactionCb ( {
4038 name : prevTransactionName ,
4139 op : 'pageload' ,
@@ -98,7 +96,7 @@ function changeStateWrapper(originalChangeStateWrapper: RouterChangeState): Wrap
9896 if ( prevTransactionName ) {
9997 tags . from = prevTransactionName ;
10098 }
101- prevTransactionName = removeQueryParams ( url ) ;
99+ prevTransactionName = stripUrlQueryAndFragment ( url ) ;
102100 activeTransaction = startTransaction ( {
103101 name : prevTransactionName ,
104102 op : 'navigation' ,
@@ -109,7 +107,3 @@ function changeStateWrapper(originalChangeStateWrapper: RouterChangeState): Wrap
109107 } ;
110108 return wrapper ;
111109}
112-
113- export function removeQueryParams ( route : string ) : string {
114- return route . replace ( QUERY_PARAM_REGEX , '' ) ;
115- }
0 commit comments