Skip to content

Commit dfa7b44

Browse files
committed
use booleans for user property in RequestData integration include option
1 parent 0596b6f commit dfa7b44

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

packages/node/src/integrations/requestdata.ts

Lines changed: 25 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,7 @@ const DEFAULT_OPTIONS = {
4647
ip: false,
4748
query_string: true,
4849
url: true,
49-
user: DEFAULT_USER_INCLUDES,
50+
user: true, // includes `id`, `username`, and `email`
5051
},
5152
transactionNamingScheme: 'methodpath',
5253
};
@@ -152,9 +153,24 @@ function formatIncludeOption(
152153
}
153154
}
154155

156+
let addReqDataUserOpt;
157+
if (user === undefined) {
158+
addReqDataUserOpt = true;
159+
} else if (typeof user === 'boolean') {
160+
addReqDataUserOpt = user;
161+
} else {
162+
const userIncludeKeys: string[] = [];
163+
for (const [key, value] of Object.entries(user)) {
164+
if (value) {
165+
userIncludeKeys.push(key);
166+
}
167+
}
168+
addReqDataUserOpt = userIncludeKeys;
169+
}
170+
155171
return {
156172
ip,
157-
user,
173+
user: addReqDataUserOpt,
158174
request: requestIncludeKeys.length !== 0 ? requestIncludeKeys : undefined,
159175
};
160176
}

0 commit comments

Comments
 (0)