diff --git a/apps/api/src/app/rate-limiting/guards/throttler.guard.ts b/apps/api/src/app/rate-limiting/guards/throttler.guard.ts index 218c2c3538c..72f7a5e6559 100644 --- a/apps/api/src/app/rate-limiting/guards/throttler.guard.ts +++ b/apps/api/src/app/rate-limiting/guards/throttler.guard.ts @@ -149,6 +149,16 @@ export class ApiRateLimitInterceptor extends ThrottlerGuard implements NestInter ) ); + res.rateLimitPolicy = { + limit, + windowDuration, + burstLimit, + algorithm, + apiRateLimitCategory, + apiRateLimitCost, + apiServiceLevel, + }; + if (isDryRun) { if (!success) { Logger.warn(`[Dry run] ${THROTTLED_EXCEPTION_MESSAGE}`, 'ApiRateLimitInterceptor'); diff --git a/libs/application-generic/src/logging/index.ts b/libs/application-generic/src/logging/index.ts index f888e84e1f9..48fce2e4ce5 100644 --- a/libs/application-generic/src/logging/index.ts +++ b/libs/application-generic/src/logging/index.ts @@ -41,9 +41,7 @@ export function getLogLevel() { if (loggingLevelArr.indexOf(logLevel) === -1) { // eslint-disable-next-line no-console console.log( - `${logLevel}is not a valid log level of ${ - loggingLevelArr - }. Reverting to info.`, + `${logLevel}is not a valid log level of ${loggingLevelArr}. Reverting to info.`, ); logLevel = 'info'; @@ -128,6 +126,21 @@ export function createNestLoggingModuleOptions( }, transport, autoLogging: !['test', 'local'].includes(process.env.NODE_ENV), + /** + * These custom props are only added to 'request completed' and 'request errored' logs. + * Logs generated during request processing won't have these props by default. + * To include these or any other custom props in mid-request logs, + * use `PinoLogger.assign()` explicitly before logging. + */ + customProps: (req: any, res: any) => ({ + user: { + userId: req?.user?._id || null, + environmentId: req?.user?.environmentId || null, + organizationId: req?.user?.organizationId || null, + }, + authScheme: req?.authScheme, + rateLimitPolicy: res?.rateLimitPolicy, + }), }, }; }