4
4
import { EventProcessor , Hub , Integration , Transaction } from '@sentry/types' ;
5
5
import { extractPathForTransaction } from '@sentry/utils' ;
6
6
7
- import {
8
- addRequestDataToEvent ,
9
- AddRequestDataToEventOptions ,
10
- DEFAULT_USER_INCLUDES ,
11
- TransactionNamingScheme ,
12
- } from '../requestdata' ;
7
+ import { addRequestDataToEvent , AddRequestDataToEventOptions , TransactionNamingScheme } from '../requestdata' ;
13
8
14
9
type RequestDataOptions = {
15
10
/**
@@ -22,7 +17,13 @@ type RequestDataOptions = {
22
17
ip ?: boolean ;
23
18
query_string ?: boolean ;
24
19
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
+ } ;
26
27
} ;
27
28
28
29
/** Whether to identify transactions by parameterized path, parameterized path with method, or handler name */
@@ -46,7 +47,11 @@ const DEFAULT_OPTIONS = {
46
47
ip : false ,
47
48
query_string : true ,
48
49
url : true ,
49
- user : DEFAULT_USER_INCLUDES ,
50
+ user : {
51
+ id : true ,
52
+ username : true ,
53
+ email : true ,
54
+ } ,
50
55
} ,
51
56
transactionNamingScheme : 'methodpath' ,
52
57
} ;
@@ -79,6 +84,14 @@ export class RequestData implements Integration {
79
84
method : true ,
80
85
...DEFAULT_OPTIONS . include ,
81
86
...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
+ } ,
82
95
} ,
83
96
} ;
84
97
}
@@ -152,9 +165,24 @@ function formatIncludeOption(
152
165
}
153
166
}
154
167
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
+
155
183
return {
156
184
ip,
157
- user,
185
+ user : addReqDataUserOpt ,
158
186
request : requestIncludeKeys . length !== 0 ? requestIncludeKeys : undefined ,
159
187
} ;
160
188
}
0 commit comments