@@ -111,32 +111,57 @@ function parseRequest(
111
111
req : {
112
112
[ key : string ] : any ;
113
113
} ,
114
+ options ?: {
115
+ version ?: boolean ;
116
+ request ?: boolean ;
117
+ serverName ?: boolean ;
118
+ user ?: boolean ;
119
+ } ,
114
120
) : SentryEvent {
115
- const preparedEvent = {
116
- ...event ,
117
- extra : {
121
+ // tslint:disable-next-line:no-parameter-reassignment
122
+ options = {
123
+ request : true ,
124
+ serverName : true ,
125
+ user : true ,
126
+ version : true ,
127
+ ...options ,
128
+ } ;
129
+
130
+ if ( options . version ) {
131
+ event . extra = {
118
132
...event . extra ,
119
133
node : global . process . version ,
120
- } ,
121
- request : {
134
+ } ;
135
+ }
136
+
137
+ if ( options . request ) {
138
+ event . request = {
122
139
...event . request ,
123
140
...extractRequestData ( req ) ,
124
- } ,
125
- server_name : global . process . env . SENTRY_NAME || os . hostname ( ) ,
126
- } ;
141
+ } ;
142
+ }
143
+
144
+ if ( options . serverName ) {
145
+ event . server_name = global . process . env . SENTRY_NAME || os . hostname ( ) ;
146
+ }
127
147
128
- if ( req . user ) {
129
- preparedEvent . user = {
148
+ if ( options . user && req . user ) {
149
+ event . user = {
130
150
...event . user ,
131
151
...extractUserData ( req ) ,
132
152
} ;
133
153
}
134
154
135
- return preparedEvent ;
155
+ return event ;
136
156
}
137
157
138
158
/** JSDoc */
139
- export function requestHandler ( ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( ) => void ) => void {
159
+ export function requestHandler ( options ?: {
160
+ version ?: boolean ;
161
+ request ?: boolean ;
162
+ serverName ?: boolean ;
163
+ user ?: boolean ;
164
+ } ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( ) => void ) => void {
140
165
return function sentryRequestMiddleware (
141
166
req : http . IncomingMessage ,
142
167
_res : http . ServerResponse ,
@@ -146,7 +171,7 @@ export function requestHandler(): (req: http.IncomingMessage, res: http.ServerRe
146
171
const hub = getHubFromCarrier ( req ) ;
147
172
hub . bindClient ( getCurrentHub ( ) . getClient ( ) ) ;
148
173
hub . configureScope ( ( scope : Scope ) => {
149
- scope . addEventProcessor ( async ( event : SentryEvent ) => parseRequest ( event , req ) ) ;
174
+ scope . addEventProcessor ( async ( event : SentryEvent ) => parseRequest ( event , req , options ) ) ;
150
175
} ) ;
151
176
local . on ( 'error' , next ) ;
152
177
local . run ( next ) ;
0 commit comments