1
1
// TODO (v8 or v9): Whenever this becomes a default integration for `@sentry/browser`, move this to `@sentry/core`. For
2
2
// now, we leave it in `@sentry/integrations` so that it doesn't contribute bytes to our CDN bundles.
3
3
4
- import { EventProcessor , Hub , Integration } from '@sentry/types' ;
4
+ import { EventProcessor , Hub , Integration , Transaction } from '@sentry/types' ;
5
+ import { extractPathForTransaction } from '@sentry/utils' ;
5
6
6
7
import {
7
8
addRequestDataToEvent ,
@@ -86,7 +87,11 @@ export class RequestData implements Integration {
86
87
* @inheritDoc
87
88
*/
88
89
public setupOnce ( addGlobalEventProcessor : ( eventProcessor : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
89
- const { include, addRequestData } = this . _options ;
90
+ // Note: In the long run, most of the logic here should probably move into the request data utility functions. For
91
+ // the moment it lives here, though, until https://github.com/getsentry/sentry-javascript/issues/5718 is addressed.
92
+ // (TL;DR: Those functions touch many parts of the repo in many different ways, and need to be clened up. Once
93
+ // that's happened, it will be easier to add this logic in without worrying about unexpected side effects.)
94
+ const { include, addRequestData, transactionNamingScheme } = this . _options ;
90
95
91
96
addGlobalEventProcessor ( event => {
92
97
const self = getCurrentHub ( ) . getIntegration ( RequestData ) ;
@@ -98,7 +103,36 @@ export class RequestData implements Integration {
98
103
return event ;
99
104
}
100
105
101
- return addRequestData ( event , req , { include : formatIncludeOption ( include ) } ) ;
106
+ const processedEvent = addRequestData ( event , req , { include : formatIncludeOption ( include ) } ) ;
107
+
108
+ // Transaction events already have the right `transaction` value
109
+ if ( event . type === 'transaction' || transactionNamingScheme === 'handler' ) {
110
+ return processedEvent ;
111
+ }
112
+
113
+ // In all other cases, use the request's associated transaction (if any) to overwrite the event's `transaction`
114
+ // value with a high-quality one
115
+ const reqWithTransaction = req as { __sentry_transaction ?: Transaction } ;
116
+ const transaction = reqWithTransaction . __sentry_transaction ;
117
+ if ( transaction ) {
118
+ // TODO (v8): Remove the nextjs check and just base it on `transactionNamingScheme` for all SDKs. (We have to
119
+ // keep it the way it is for the moment, because changing the names of transactions in Sentry has the potential
120
+ // to break things like alert rules.)
121
+ const shouldIncludeMethodInTransactionName =
122
+ event . sdk ?. name === '@sentry/nextjs'
123
+ ? transaction . name . startsWith ( '/api' )
124
+ : transactionNamingScheme !== 'path' ;
125
+
126
+ const [ transactionValue ] = extractPathForTransaction ( req , {
127
+ path : true ,
128
+ method : shouldIncludeMethodInTransactionName ,
129
+ customRoute : transaction . name ,
130
+ } ) ;
131
+
132
+ processedEvent . transaction = transactionValue ;
133
+ }
134
+
135
+ return processedEvent ;
102
136
} ) ;
103
137
}
104
138
}
0 commit comments