44import { EventProcessor , Hub , Integration , Transaction } from '@sentry/types' ;
55import { extractPathForTransaction } from '@sentry/utils' ;
66
7- import {
8- addRequestDataToEvent ,
9- AddRequestDataToEventOptions ,
10- DEFAULT_USER_INCLUDES ,
11- TransactionNamingScheme ,
12- } from '../requestdata' ;
7+ import { addRequestDataToEvent , AddRequestDataToEventOptions , TransactionNamingScheme } from '../requestdata' ;
138
149type RequestDataOptions = {
1510 /**
@@ -22,7 +17,13 @@ type RequestDataOptions = {
2217 ip ?: boolean ;
2318 query_string ?: boolean ;
2419 url ?: boolean ;
25- user ?: boolean | Array < typeof DEFAULT_USER_INCLUDES [ number ] > ;
20+ user ?:
21+ | boolean
22+ | {
23+ id ?: boolean ;
24+ username ?: boolean ;
25+ email ?: boolean ;
26+ } ;
2627 } ;
2728
2829 /** Whether to identify transactions by parameterized path, parameterized path with method, or handler name */
@@ -46,7 +47,11 @@ const DEFAULT_OPTIONS = {
4647 ip : false ,
4748 query_string : true ,
4849 url : true ,
49- user : DEFAULT_USER_INCLUDES ,
50+ user : {
51+ id : true ,
52+ username : true ,
53+ email : true ,
54+ } ,
5055 } ,
5156 transactionNamingScheme : 'methodpath' ,
5257} ;
@@ -79,6 +84,14 @@ export class RequestData implements Integration {
7984 method : true ,
8085 ...DEFAULT_OPTIONS . include ,
8186 ...options . include ,
87+ user :
88+ options . include && typeof options . include . user === 'boolean'
89+ ? options . include . user
90+ : {
91+ ...DEFAULT_OPTIONS . include . user ,
92+ // Unclear why TS still thinks `options.include.user` could be a boolean at this point
93+ ...( ( options . include || { } ) . user as Record < string , boolean > ) ,
94+ } ,
8295 } ,
8396 } ;
8497 }
@@ -152,9 +165,24 @@ function formatIncludeOption(
152165 }
153166 }
154167
168+ let addReqDataUserOpt ;
169+ if ( user === undefined ) {
170+ addReqDataUserOpt = true ;
171+ } else if ( typeof user === 'boolean' ) {
172+ addReqDataUserOpt = user ;
173+ } else {
174+ const userIncludeKeys : string [ ] = [ ] ;
175+ for ( const [ key , value ] of Object . entries ( user ) ) {
176+ if ( value ) {
177+ userIncludeKeys . push ( key ) ;
178+ }
179+ }
180+ addReqDataUserOpt = userIncludeKeys ;
181+ }
182+
155183 return {
156184 ip,
157- user,
185+ user : addReqDataUserOpt ,
158186 request : requestIncludeKeys . length !== 0 ? requestIncludeKeys : undefined ,
159187 } ;
160188}
0 commit comments