Open
Conversation
Coverage Report
File Coverage |
There was a problem hiding this comment.
Pull request overview
Adds request-scoped logging to improve observability by propagating a request ID (reqId) through HTTP handling and including both reqId and query duration (durationMs) in database logs.
Changes:
- Introduce AsyncLocalStorage-based reqId context and register it as an
onRequesthook. - Add
getRequestLogger()and migrate middlewares/policies to use request-scoped logging. - Enable Sequelize query benchmarking and emit query logs with
durationMs; extend logging config withmiddlewares/policiesmodules.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/repository/storage/postgres/orm/sequelize/index.ts | Enables benchmarked Sequelize logging and logs durationMs via request-scoped logger. |
| src/presentation/http/policies/userCanEdit.ts | Adds request-scoped logging around policy decisions. |
| src/presentation/http/policies/notePublicOrUserInTeam.ts | Adds request-scoped logging for note access policy flow. |
| src/presentation/http/policies/authRequired.ts | Adds request-scoped logging for authentication requirement policy. |
| src/presentation/http/middlewares/noteSettings/useNoteSettingsResolver.ts | Switches middleware logging to request-scoped logger. |
| src/presentation/http/middlewares/noteSettings/useMemberRoleResolver.ts | Switches to request-scoped logger and improves error message formatting. |
| src/presentation/http/middlewares/note/useNoteResolver.ts | Switches middleware logging to request-scoped logger. |
| src/presentation/http/middlewares/common/userIdResolver.ts | Removes injected logger parameter and uses request-scoped logger inside hook. |
| src/presentation/http/middlewares/common/reqIdContext.ts | New middleware to establish reqId async context per request. |
| src/presentation/http/http-api.ts | Registers reqId context middleware and updates userId resolver wiring. |
| src/infrastructure/logging/reqId.context.ts | New AsyncLocalStorage store + helper to fetch current reqId. |
| src/infrastructure/logging/index.ts | Adds getRequestLogger() which enriches logs with reqId when present. |
| src/infrastructure/config/index.ts | Extends LoggingConfig schema/defaults to include middlewares and policies. |
| eslint.config.mjs | Tightens Node built-in feature linting via n/no-unsupported-features/node-builtins. |
| app-config.yaml | Adds log levels for new middlewares and policies logger modules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+37
| benchmark: true, | ||
| logging: (message, timing) => { | ||
| const logger = getRequestLogger('database'); | ||
|
|
||
| logger.info( | ||
| { durationMs: timing }, | ||
| message | ||
| ); | ||
| }, |
Comment on lines
+45
to
+56
| export function getRequestLogger(moduleName: keyof LoggingConfig): pino.Logger { | ||
| const baseLogger = getLogger(moduleName); | ||
| const reqId = getCurrentReqId(); | ||
|
|
||
| if (reqId != null && reqId !== '') { | ||
| return baseLogger.child({ | ||
| reqId, | ||
| }); | ||
| } | ||
|
|
||
| return baseLogger; | ||
| } |
| return await reply.unauthorized(); | ||
| } | ||
|
|
||
| logger.info(`User authenticated with ID: ${userId}`); |
| return await reply.forbidden(); | ||
| } | ||
|
|
||
| logger.info('User edit permission check completed successfully'); |
| return await reply.forbidden(); | ||
| } | ||
| } | ||
| logger.info('Note access check completed successfully'); |
Comment on lines
+42
to
+44
| logger.error(`Can not resolve Member role by note [id = ${request.note.id}] and user [id = ${request.userId}]`); | ||
| } else { | ||
| logger.error('Can not resolve Member role - note or user ID not available'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
Details: