Skip to content

Commit 3f71eb3

Browse files
feat(application-generic): Bump Pino
Bump Pino and fix duplicate "user" keys in the final JSON Log entry.
1 parent 3d54da4 commit 3f71eb3

File tree

3 files changed

+376
-509
lines changed

3 files changed

+376
-509
lines changed

libs/application-generic/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
"mixpanel": "^0.17.0",
8686
"nanoid": "^3.1.20",
8787
"nestjs-otel": "6.1.1",
88-
"nestjs-pino": "4.1.0",
88+
"nestjs-pino": "4.3.0",
8989
"node-fetch": "^3.2.10",
90-
"pino-http": "^8.3.3",
91-
"pino-pretty": "^9.4.0",
90+
"pino-http": "^10.4.0",
91+
"pino-pretty": "^13.0.0",
9292
"recursive-diff": "^1.0.8",
9393
"redlock": "5.0.0-beta.2",
9494
"rrule": "^2.7.2",

libs/application-generic/src/logging/index.ts

+21-28
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function getLoggingVariables(): ILoggingVariables {
6969
};
7070
}
7171

72-
export function createNestLoggingModuleOptions(settings: ILoggerSettings): Params {
72+
export function createNestLoggingModuleOptions(settings: { serviceName: string; version: string }): Params {
7373
const values: ILoggingVariables = getLoggingVariables();
7474

7575
let redactFields: string[] = sensitiveFields.map((val) => val);
@@ -99,7 +99,6 @@ export function createNestLoggingModuleOptions(settings: ILoggerSettings): Param
9999
level: values.level,
100100
redact: {
101101
paths: redactFields,
102-
censor: customRedaction,
103102
},
104103
base: {
105104
pid: process.pid,
@@ -116,32 +115,26 @@ export function createNestLoggingModuleOptions(settings: ILoggerSettings): Param
116115
* To include these or any other custom props in mid-request logs,
117116
* use `PinoLogger.assign(<props>)` explicitly before logging.
118117
*/
119-
customProps: (req: any, res: any) => ({
120-
user: {
121-
userId: req?.user?._id || null,
122-
environmentId: req?.user?.environmentId || null,
123-
organizationId: req?.user?.organizationId || null,
124-
apiServiceLevel: req?.user?.apiServiceLevel || null,
125-
},
126-
authScheme: req?.authScheme,
127-
rateLimitPolicy: res?.rateLimitPolicy,
128-
}),
118+
customProps: (req: any, res: any) => {
119+
/**
120+
* This is a workaround to avoid duplicate keys in the final JSON log entry
121+
* See https://github.com/pinojs/pino-http/issues/216
122+
*/
123+
if (req?.user) {
124+
return {
125+
user: {
126+
userId: req?.user?._id || null,
127+
environmentId: req?.user?.environmentId || null,
128+
organizationId: req?.user?.organizationId || null,
129+
apiServiceLevel: req?.user?.apiServiceLevel || null,
130+
},
131+
authScheme: req?.authScheme,
132+
rateLimitPolicy: res?.rateLimitPolicy,
133+
};
134+
}
135+
136+
return {};
137+
},
129138
},
130139
};
131140
}
132-
133-
const customRedaction = (value: any, path: string[]) => {
134-
/*
135-
* Logger.
136-
* if (obj.email && typeof obj.email === 'string') {
137-
* obj.email = '[REDACTED]';
138-
* }
139-
*
140-
* return JSON.parse(JSON.stringify(obj));
141-
*/
142-
};
143-
144-
interface ILoggerSettings {
145-
serviceName: string;
146-
version: string;
147-
}

0 commit comments

Comments
 (0)