Skip to content

Commit d8b602f

Browse files
committed
use booleans for user property in RequestData integration include option
1 parent 8408a3b commit d8b602f

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

packages/node/src/integrations/requestdata.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
import { EventProcessor, Hub, Integration, Transaction } from '@sentry/types';
55
import { 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

149
type 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

Comments
 (0)