1
- import { Primitive , Transaction , TransactionContext } from '@sentry/types' ;
1
+ import { Primitive , Transaction , TransactionContext , TransactionSource } from '@sentry/types' ;
2
2
import { getGlobalObject } from '@sentry/utils' ;
3
3
4
4
import { Location , ReactRouterInstrumentation } from './types' ;
@@ -44,16 +44,24 @@ export function reactRouterV3Instrumentation(
44
44
45
45
// Have to use global.location because history.location might not be defined.
46
46
if ( startTransactionOnPageLoad && global && global . location ) {
47
- normalizeTransactionName ( routes , global . location as unknown as Location , match , ( localName : string ) => {
48
- prevName = localName ;
49
- activeTransaction = startTransaction ( {
50
- name : prevName ,
51
- op : 'pageload' ,
52
- tags : {
53
- 'routing.instrumentation' : 'react-router-v3' ,
54
- } ,
55
- } ) ;
56
- } ) ;
47
+ normalizeTransactionName (
48
+ routes ,
49
+ global . location as unknown as Location ,
50
+ match ,
51
+ ( localName : string , source : TransactionSource = 'url' ) => {
52
+ prevName = localName ;
53
+ activeTransaction = startTransaction ( {
54
+ name : prevName ,
55
+ op : 'pageload' ,
56
+ tags : {
57
+ 'routing.instrumentation' : 'react-router-v3' ,
58
+ } ,
59
+ } ) ;
60
+ if ( activeTransaction ) {
61
+ activeTransaction . setMetadata ( { source } ) ;
62
+ }
63
+ } ,
64
+ ) ;
57
65
}
58
66
59
67
if ( startTransactionOnLocationChange && history . listen ) {
@@ -68,13 +76,16 @@ export function reactRouterV3Instrumentation(
68
76
if ( prevName ) {
69
77
tags . from = prevName ;
70
78
}
71
- normalizeTransactionName ( routes , location , match , ( localName : string ) => {
79
+ normalizeTransactionName ( routes , location , match , ( localName : string , source : TransactionSource = 'url' ) => {
72
80
prevName = localName ;
73
81
activeTransaction = startTransaction ( {
74
82
name : prevName ,
75
83
op : 'navigation' ,
76
84
tags,
77
85
} ) ;
86
+ if ( activeTransaction ) {
87
+ activeTransaction . setMetadata ( { source } ) ;
88
+ }
78
89
} ) ;
79
90
}
80
91
} ) ;
@@ -89,7 +100,7 @@ function normalizeTransactionName(
89
100
appRoutes : Route [ ] ,
90
101
location : Location ,
91
102
match : Match ,
92
- callback : ( pathname : string ) => void ,
103
+ callback : ( pathname : string , source ?: TransactionSource ) => void ,
93
104
) : void {
94
105
let name = location . pathname ;
95
106
match (
@@ -108,7 +119,7 @@ function normalizeTransactionName(
108
119
}
109
120
110
121
name = routePath ;
111
- return callback ( name ) ;
122
+ return callback ( name , 'route' ) ;
112
123
} ,
113
124
) ;
114
125
}
0 commit comments