-
Notifications
You must be signed in to change notification settings - Fork 347
migration: migrate to Pino (logger) #1269
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
Conversation
🦋 Changeset detectedLatest commit: 1a4be4a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| }, | ||
| }); | ||
| } else { | ||
| targets.push({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In non-dev environments, the logger outputs a JSON string to stdout
Pull Request Review: Migration from Winston to PinoThis PR migrates the HyperDX API logging infrastructure from Winston to Pino. Overall, this is a well-executed migration with good attention to detail. Strengths
Issues and Concerns1. Critical: Type Safety Issue in logger.tsLocation: packages/api/src/utils/logger.ts:21 Using any[] defeats TypeScript type safety. Recommendation: Use proper typing from Pino (TransportTargetOptions[]) 2. Potential Bug: Transport Configuration LogicLocation: packages/api/src/utils/logger.ts:47-54 The targets.length === 0 case should never happen but if it does, returning undefined will cause fallback to default console logging. Either remove the check or add a fallback default transport. 3. Missing Error Handling in usageStats.tsLocation: packages/api/src/tasks/usageStats.ts:162-164 Silently ignoring errors is acceptable but should be logged at debug level for troubleshooting. 4. Inconsistent Error Logging PatternLocation: packages/api/src/routers/api/root.ts:201 Variable e is not typed and might not be an Error object. Use serializeError consistently. 5. Missing TestsNo tests were added to verify the new Pino logger configuration works correctly across different environments. Recommendation: Add unit tests for logger initialization, transport selection logic, structured logging format, and error serialization. Security ReviewNo Security Issues Detected - No credentials exposed, proper error serialization, no injection vulnerabilities introduced. Performance AnalysisPositive Impact - Pino is significantly faster than Winston (up to 10x in benchmarks). Structured JSON logging is more efficient. Implementation properly optimizes for single vs multiple transports. Code QualityGenerally follows CLAUDE.md guidelines with proper TypeScript typing (except any[] issue), consistent error handling patterns, and clear code organization. Minor style issues: unused err parameter in customErrorMessage function, inconsistent error variable naming (e vs err). Final RecommendationsMust Fix Before Merge
Should Fix (High Priority)
Nice to Have (Low Priority)
ConclusionThis is a high-quality migration that follows best practices and properly implements structured logging with Pino. The code is clean, well-organized, and demonstrates good understanding of both ecosystems. Recommendation: Approve with minor changes - Fix the type safety issue and add basic tests, then ready to merge. Estimated Risk: Low - Changes are well-contained, backwards compatible in log output, and migration pattern is consistent throughout. Great work! |
E2E Test Results✅ All tests passed • 25 passed • 3 skipped • 226s
|
Pull Request Review - Winston to Pino MigrationThank you for this comprehensive migration! This is a solid improvement to the logging infrastructure. StrengthsWell-Structured Migration
Improved Logging Configuration
HTTP Logging Enhancements
Consistent Error Patterns
Issues and Recommendations1. Type Safety Issue in logger.ts (Line 21) 2. Potential Configuration Edge Case 3. Missing Error Type in customLogLevel 4. Test Coverage Consideration 5. Usage Stats Logger (usageStats.ts) Security ReviewNo security concerns identified:
Performance ConsiderationsPerformance improvements expected:
Testing RecommendationsBefore merging, please verify:
SummaryThis is a high-quality migration with consistent patterns throughout. The main concerns are type safety improvements and edge case handling in logger.ts, plus test coverage verification. The migration properly addresses issue 1035 and will provide better logging performance. Recommendation: Approve with minor changes - address the type safety issues and edge case handling, then this is ready to merge. |
pulpdrew
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one suggestion -
There are a few places throughout the codebase that call logger.info({ message: '...' }). In winston, that made sense since winston treated the message field as significant. Pino on the other hand seems to use msg as the message field in logged objects. It might be good to be consistent and replace message with msg.
Example: https://github.com/hyperdxio/hyperdx/blob/main/packages/api/src/tasks/checkAlerts.ts#L96
| const user = req.user; | ||
| if (user) { | ||
| return { | ||
| userId: user._id?.toString(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likesetTraceAttributes (
hyperdx/packages/api/src/middleware/auth.ts
Lines 111 to 114 in f5f0b4f
| setTraceAttributes({ | |
| userId: req.user?._id.toString(), | |
| userEmail: req.user?.email, | |
| }); |
Good call! Done |
Summary
Migrates the HyperDX API and related services from Winston to Pino for standardized,
faster, and more structured logging with improved OpenTelemetry integration.
Changes
Core Migration
transport
newer OTel SDK)
Logger Configuration (packages/api/src/utils/logger.ts)
Production:
Development:
HTTP Logging:
Error Logging Updates
Updated error logging patterns throughout the codebase to follow Pino's structured
logging conventions:
// Before (Winston)
logger.error('Error message:', error);
// After (Pino)
logger.error({ err: error }, 'Error message');
Ref: HDX-2588
This PR should also address issue: #1035