Skip to content

Commit 462d072

Browse files
committed
Merge branch 'master' of github.com:getsentry/sentry-javascript
2 parents abce9ce + fdb64e2 commit 462d072

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [hub] fix: Correctly store and retrieve Hub from domain when one is active
2828
- [hub] fix: Copy over user data when cloning scope
2929
- [node] feat: Allow requestHandler to be configured
30+
- [node] feat: Allow pick any user attributes from requestHandler
3031
- [node] feat: Make node transactions a pluggable integration with tests
3132
- [node] feat: Transactions handling for RequestHandler in Express/Hapi
3233
- [node] fix: Dont wrap native modules more than once to prevent leaks

packages/node/src/handlers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
114114
return request;
115115
}
116116

117+
/** Default user keys that'll be used to extract data from the request */
118+
const DEFAULT_USER_KEYS = ['id', 'username', 'email'];
119+
117120
/** JSDoc */
118-
function extractUserData(req: { [key: string]: any }): { [key: string]: string } {
121+
function extractUserData(req: { [key: string]: any }, keys: boolean | string[]): { [key: string]: string } {
119122
const user: { [key: string]: string } = {};
123+
const attributes = Array.isArray(keys) ? keys : DEFAULT_USER_KEYS;
120124

121-
['id', 'username', 'email'].forEach(key => {
125+
attributes.forEach(key => {
122126
if ({}.hasOwnProperty.call(req.user, key)) {
123127
user[key] = (req.user as { [key: string]: string })[key];
124128
}
@@ -151,7 +155,7 @@ function parseRequest(
151155
request?: boolean;
152156
serverName?: boolean;
153157
transaction?: boolean | TransactionTypes;
154-
user?: boolean;
158+
user?: boolean | string[];
155159
version?: boolean;
156160
},
157161
): SentryEvent {
@@ -186,7 +190,7 @@ function parseRequest(
186190
if (options.user && req.user) {
187191
event.user = {
188192
...event.user,
189-
...extractUserData(req),
193+
...extractUserData(req, options.user),
190194
};
191195
}
192196

@@ -205,7 +209,7 @@ export function requestHandler(options?: {
205209
request?: boolean;
206210
serverName?: boolean;
207211
transaction?: boolean | TransactionTypes;
208-
user?: boolean;
212+
user?: boolean | string[];
209213
version?: boolean;
210214
}): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void {
211215
return function sentryRequestMiddleware(

0 commit comments

Comments
 (0)