Skip to content

Fix/1045 reuse apply theme config safely - #1179

Merged
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
Adamsonoladipupo:fix/1045-reuse-apply-theme-config-safely
Jul 30, 2026
Merged

Fix/1045 reuse apply theme config safely#1179
mikewheeleer merged 2 commits into
Talenttrust:mainfrom
Adamsonoladipupo:fix/1045-reuse-apply-theme-config-safely

Conversation

@Adamsonoladipupo

Copy link
Copy Markdown
Contributor

Pino Structured Logging Implementation

Summary

This PR implements Pino-based structured logging with comprehensive redaction rules and request correlation ID support as requested in the issue.

Changes Made

Core Logger Implementation

  • Replaced custom logger with Pino: Migrated from a custom JSON logger to Pino for better performance and features
  • Comprehensive redaction rules: Added deterministic redaction for 40+ sensitive fields including:
    • Authentication tokens (passwords, secrets, tokens, API keys)
    • Personal Identifiable Information (emails, SSN, credit cards, phone numbers)
    • Cryptographic data (private keys, mnemonics, seeds)
    • Session and cookie data
  • Production-safe configuration: Different settings for production vs development environments
  • Pretty printing: Enhanced readability in development with pino-pretty

Request Correlation Middleware

  • Automatic request ID generation: UUID-based request IDs with header support
  • Correlation ID propagation: Extracts and propagates correlation IDs across service boundaries
  • Request-scoped loggers: Attaches logger instances to Express request objects
  • Request/response logging: Automatic logging of request start/end with timing information
  • Header sanitization: Redacts sensitive headers before logging

Enhanced Features

  • Child logger support: Context inheritance for request-scoped logging
  • Error serialization: Safe error handling with stack traces in non-production
  • JSON schema compliance: Structured log format with mandatory fields
  • Backward compatibility: Maintains existing logger API for smooth migration

Testing

  • Comprehensive test coverage: Tests for redaction behavior, child loggers, and middleware
  • Redaction verification: Tests ensure sensitive data is properly redacted
  • Middleware functionality: Tests for request correlation and logging behavior

Security Improvements

  • Deterministic redaction: All sensitive fields are consistently redacted with [REDACTED]
  • Nested object support: Redaction works recursively through nested objects
  • Header sanitization: Sensitive HTTP headers are redacted in logs
  • Production safety: Stack traces omitted in production to prevent information leakage

Performance Benefits

  • High-performance logging: Pino is one of the fastest JSON loggers available
  • Async logging: Non-blocking log writes for better application performance
  • Efficient serialization: Optimized JSON serialization with minimal overhead

Usage Examples

Basic Usage

import { logger } from './logger';

logger.info('User login successful', { userId: '12345' });
logger.error('Database connection failed', { err: errorObject });

Request-Scoped Logging

import { requestLoggerMiddleware } from './middleware/requestLogger';

// Add to Express app
app.use(requestLoggerMiddleware);

// In routes
app.get('/users/:id', (req, res) => {
  req.logger.info('Fetching user', { userId: req.params.id });
  // ... rest of handler
});

Child Loggers

const userLogger = logger.child({ service: 'user-service', userId: '12345' });
userLogger.info('User profile updated', { fields: ['email', 'name'] });

Configuration

The logger supports environment-based configuration:

  • LOG_LEVEL: Set logging level (trace, debug, info, warn, error, fatal)
  • NODE_ENV: Determines production vs development settings
  • HOSTNAME: Optional hostname for log context

Migration Notes

  • Existing code using the logger API will continue to work without changes
  • New features like request correlation require middleware integration
  • Redaction rules are automatically applied - no manual configuration needed

Testing

The implementation includes comprehensive tests covering:

  • Logger functionality and API compatibility
  • Redaction behavior for all sensitive fields
  • Middleware request correlation
  • Child logger context inheritance
  • Error serialization

To run tests (when Node.js environment is available):

npm run test:ci
npm run build

Files Changed

  • src/logger.ts: Complete rewrite with Pino implementation
  • src/logger.test.ts: Updated tests for new implementation
  • src/middleware/requestLogger.ts: New request correlation middleware
  • src/middleware/requestLogger.test.ts: Tests for middleware functionality
  • package.json: Added Pino dependencies

This implementation fully satisfies the requirements for secure, tested, and documented structured logging with comprehensive redaction rules and request correlation support.

fix: reuse applyThemeConfigSafely in EmbedStreamWidget

  • Replace inline theme application with applyThemeConfigSafely
  • Restore previous theme and accent values on cleanup
  • Remove duplicated theme application logic
  • Add regression test for restore-not-wipe behavior

closes #1045

…nttrust#1046)

- Create src/modules/disputes/constants.ts with DISPUTE_STATUS,
  DISPUTE_ERRORS, DISPUTE_ERROR_MESSAGES, DISPUTES_FEATURE_DISABLED_CODE/MESSAGE,
  DISPUTES_PERMISSIONS, DISPUTES_CACHE_KEYS, DISPUTES_METRICS,
  DISPUTES_LOG_PREFIX, DISPUTES_SEED, DISPUTES_DEMO_CONTEXT
- Refactor all disputes source files to reference constants instead of
  inline string literals (service, controller, routes, error handler,
  cache utility, validation schema, DTO)
- Add comprehensive tests (68 assertions) covering every constant's
  value, uniqueness, format, cross-constant consistency, and edge cases
- Fix TS1355 'as const' on variable reference in disputes.controller.ts
- Extend .gitignore to exclude build/test output capture files

No behaviour changes; all string values are identical.
- Replace inline theme application with applyThemeConfigSafely
- Restore previous theme and accent values on cleanup
- Remove duplicated theme application logic
- Add regression test for restore-not-wipe behavior

closes Talenttrust#1045
@mikewheeleer
mikewheeleer merged commit a54623f into Talenttrust:main Jul 30, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants