Skip to content
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

Enhance Logging with Correlation IDs and Contextual Information #126

Open
monilpat opened this issue Dec 21, 2024 · 0 comments
Open

Enhance Logging with Correlation IDs and Contextual Information #126

monilpat opened this issue Dec 21, 2024 · 0 comments
Labels

Comments

@monilpat
Copy link
Collaborator

Feature Request

Is your feature request related to a problem? Please describe.

Current logging practices do not include correlation IDs or sufficient contextual information, making it difficult to trace requests across distributed systems and understand the full context of log entries.

Describe the solution you'd like

Implement enhancements to the logging system to include correlation IDs for distributed tracing and enrich log messages with contextual information. This can be achieved by:

  • Generating a unique correlation ID for each request and propagating it across service boundaries.
  • Augmenting log entries with relevant context, such as user IDs, session information, and transaction details.
  • Utilizing structured logging formats like JSON to facilitate easier parsing and analysis.

Code Example

const winston = require('winston');
const { v4: uuidv4 } = require('uuid');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: 'application.log' })
  ]
});

function logRequest(req, res, next) {
  req.correlationId = uuidv4();
  logger.info('Incoming request', { correlationId: req.correlationId, userId: req.user?.id });
  next();
}

Describe alternatives you've considered

  • Continuing with the current logging structure, but this limits the ability to trace and analyze logs effectively.
  • Using external APM tools, which may be costly and add complexity.

Additional context

Enhancing the logging with correlation IDs and context will improve observability, facilitate debugging, and optimize performance monitoring across distributed systems.

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant