Skip to content

feat(log): Implement structured logging #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: crl-main
Choose a base branch
from

Conversation

ibreakthecloud
Copy link
Member

@ibreakthecloud ibreakthecloud commented Apr 11, 2025

Add structured JSON logging with request IDs, timestamps, and context across:

  • Logger service (standardized format, request tracking)
  • Request middleware (HTTP metadata, duration)
  • Webhook processing (timing metrics, status tracking)
  • Service layer (CLA, Repo, Webhook services)
  • Controller layer (error handling, context)

//todo: Add screenshots

Improves observability, debugging, and monitoring in Datadog while maintaining existing functionality.
Part of CODESYS-80
Note: Some codes are generated by Cursor.

@ibreakthecloud ibreakthecloud force-pushed the logging-fix branch 2 times, most recently from 21d94d1 to 049ba9d Compare April 14, 2025 07:44
@coveralls
Copy link

coveralls commented Apr 14, 2025

Pull Request Test Coverage Report for Build 14571679809

Details

  • 38 of 51 (74.51%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 71.091%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server/src/services/logger.js 38 51 74.51%
Files with Coverage Reduction New Missed Lines %
src/server/src/services/logger.js 1 63.04%
Totals Coverage Status
Change from base Build 13179434831: 0.02%
Covered Lines: 149
Relevant Lines: 194

💛 - Coveralls

Add structured JSON logging with request IDs, timestamps, and context across:
- Logger service (standardized format, request tracking)
- Request middleware (HTTP metadata, duration)
- Webhook processing (timing metrics, status tracking)
- Service layer (CLA, Repo, Webhook services)
- Controller layer (error handling, context)

Improves observability, debugging, and monitoring in Datadog while maintaining existing functionality.
@ibreakthecloud ibreakthecloud changed the title wip: logging: more verbose logging feat(log): Implement structured logging Apr 14, 2025
@ibreakthecloud ibreakthecloud marked this pull request as ready for review April 15, 2025 06:57
Copy link

@celiala celiala left a comment

Choose a reason for hiding this comment

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

overall LGTM -- some questions (inline)

@@ -6,10 +6,19 @@ const logger = require('../logger')

function rateLimitLogger(octokit) {
octokit.hook.after('request', async (response, options) => {
logger.info(`${options.method} ${options.url}: ${response.status} || Rate Limit: ${response.headers['x-ratelimit-remaining']}/${response.headers['x-ratelimit-limit']} reset at ${new Date(Number(response.headers['x-ratelimit-reset']) * 1000).toTimeString()}`)
logger.info({
Copy link

Choose a reason for hiding this comment

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

nice improvement!

} catch (error) {
logger.warn(new Error(error).stack)
logger.error({
Copy link

Choose a reason for hiding this comment

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

event is WARNING, but logger level is logger.error -- should these match (i.e. both warning or both error)? or keep as-is?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch!
changing logger.error to logger.warn to match previous logging level.

error: error,
msg: 'Warning in CLA operation'
})
logger.warn({
Copy link

Choose a reason for hiding this comment

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

any reason to log this twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

this seems like a mistake, fixing this.

error: error,
msg: 'Warning in CLA operation'
})
logger.warn({
Copy link

Choose a reason for hiding this comment

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

(same: double-logging)

Copy link
Member Author

Choose a reason for hiding this comment

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

@rail
Copy link
Member

rail commented Apr 22, 2025

LGTM. What do you think about upstreaming this feature? If we decide yes, we should follow the guidelines: https://docs.google.com/document/d/1gnHXsXvLnynCDrDIvhJgQmPAvkdkC_A8/edit?tab=t.0

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.

4 participants