@@ -26,7 +26,7 @@ function extractTransaction(req: { [key: string]: any }, type: boolean | Transac
2626 stack : [
2727 {
2828 name : string ;
29- }
29+ } ,
3030 ] ;
3131 } ;
3232 } ;
@@ -51,7 +51,7 @@ function extractTransaction(req: { [key: string]: any }, type: boolean | Transac
5151}
5252
5353/** JSDoc */
54- function extractRequestData ( req : { [ key : string ] : any } ) : { [ key : string ] : string } {
54+ function extractRequestData ( req : { [ key : string ] : any } , keys : boolean | string [ ] ) : { [ key : string ] : string } {
5555 // headers:
5656 // node, express: req.headers
5757 // koa: req.header
@@ -112,6 +112,17 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
112112 url : absoluteUrl ,
113113 } ;
114114
115+ const attributes = Array . isArray ( keys ) ? keys : [ ] ;
116+
117+ if ( attributes . length ) {
118+ Object . keys ( request ) . forEach ( key => {
119+ /** Remove any of the unspecified keys in the options from the request interface */
120+ if ( ! attributes . includes ( key ) ) {
121+ delete request [ key ] ;
122+ }
123+ } ) ;
124+ }
125+
115126 return request ;
116127}
117128
@@ -161,7 +172,7 @@ export function parseRequest(
161172 [ key : string ] : any ;
162173 } ,
163174 options ?: {
164- request ?: boolean ;
175+ request ?: boolean | string [ ] ;
165176 serverName ?: boolean ;
166177 transaction ?: boolean | TransactionTypes ;
167178 user ?: boolean | string [ ] ;
@@ -188,7 +199,7 @@ export function parseRequest(
188199 if ( options . request ) {
189200 event . request = {
190201 ...event . request ,
191- ...extractRequestData ( req ) ,
202+ ...extractRequestData ( req , options . request ) ,
192203 } ;
193204 }
194205
0 commit comments