Skip to content

Update logs#299

Open
7eliassen wants to merge 7 commits intomainfrom
chore/logs-and-optimization
Open

Update logs#299
7eliassen wants to merge 7 commits intomainfrom
chore/logs-and-optimization

Conversation

@7eliassen
Copy link

Changes:

  • Added execution time tracking (durationMs) for database queries.
  • Implemented request ID (reqId) propagation to middlewares, policies, and database queries.
  • Added logging for policy executions and included middleware/policy modules in the logging configuration

Details:

  • Created reqId.context.ts for async context management
  • Added reqIdContext middleware to inject request IDs
  • Modified Sequelize configuration to include durationMs and reqId in query logs
  • Updated eslint config

@github-actions
Copy link

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 85.95% (🎯 80%)
⬆️ +0.04%
9017 / 10490
🔵 Statements 85.95% (🎯 80%)
⬆️ +0.04%
9017 / 10490
🔵 Functions 79.77% (🎯 80%)
⬆️ +0.24%
280 / 351
🔵 Branches 84.94% (🎯 80%)
⬆️ +0.37%
457 / 538
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/infrastructure/config/index.ts 98.99%
⬆️ +0.02%
50%
🟰 ±0%
100%
🟰 ±0%
98.99%
⬆️ +0.02%
189-190
src/infrastructure/logging/index.ts 95%
⬆️ +2.32%
71.42%
⬆️ +38.09%
100%
🟰 ±0%
95%
⬆️ +2.32%
8, 32-33
src/infrastructure/logging/reqId.context.ts 100% 100% 100% 100%
src/presentation/http/http-api.ts 96.08%
⬆️ +0.02%
90.32%
🟰 ±0%
93.75%
🟰 ±0%
96.08%
⬆️ +0.02%
103-111, 122-123, 325-326, 350-351
src/presentation/http/middlewares/common/reqIdContext.ts 100% 100% 100% 100%
src/presentation/http/middlewares/common/userIdResolver.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/presentation/http/middlewares/note/useNoteResolver.ts 97.22%
⬇️ -0.14%
85.71%
🟰 ±0%
100%
🟰 ±0%
97.22%
⬇️ -0.14%
59-60
src/presentation/http/middlewares/noteSettings/useMemberRoleResolver.ts 78.84%
⬇️ -7.69%
71.42%
🟰 ±0%
100%
🟰 ±0%
78.84%
⬇️ -7.69%
27-28, 41-49
src/presentation/http/middlewares/noteSettings/useNoteSettingsResolver.ts 94.87%
⬇️ -0.47%
80%
🟰 ±0%
100%
🟰 ±0%
94.87%
⬇️ -0.47%
25-26
src/presentation/http/policies/authRequired.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/presentation/http/policies/notePublicOrUserInTeam.ts 94.44%
⬇️ -3.33%
88.88%
⬆️ +1.38%
100%
🟰 ±0%
94.44%
⬇️ -3.33%
20-22
src/presentation/http/policies/userCanEdit.ts 93.61%
⬇️ -3.68%
85.71%
⬆️ +2.38%
100%
🟰 ±0%
93.61%
⬇️ -3.68%
29-31
src/repository/storage/postgres/orm/sequelize/index.ts 97.05%
⬆️ +0.39%
83.33%
⬆️ +3.33%
100%
🟰 ±0%
97.05%
⬆️ +0.39%
58-59
Generated in workflow #909 for commit 5d9b45a by the Vitest Coverage Report Action

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 onRequest hook.
  • Add getRequestLogger() and migrate middlewares/policies to use request-scoped logging.
  • Enable Sequelize query benchmarking and emit query logs with durationMs; extend logging config with middlewares/policies modules.

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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants