-
Notifications
You must be signed in to change notification settings - Fork 772
Add performance monitoring (prometheus for metrics and winston for logging) #1394
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
base: main
Are you sure you want to change the base?
Conversation
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.
🧪 PR Review is completed: Review of the new APM implementation with Prometheus and Winston. Key issues found in environment variable handling, error logging, and logger initialization.
Skipped files
package-lock.json: Skipped file patternwrangler.toml: Skipped file pattern
⬇️ Low Priority Suggestions (4)
src/apm/loki/logger.ts
Location:
src/apm/loki/logger.ts(Lines 31-31)🟡 Error Handling
Issue: The broad
try-catchblock inLokiLoggerinitialization swallows all errors and sets the logger tonull, which can lead to silent failures and make debugging difficult.Fix: Log specific errors during initialization to help with debugging while still providing a fallback.
Impact: Improves debuggability and error visibility
- LokiLogger = null; + console.error('[LOKI LOGGER] Failed to initialize Loki logger:', error); + LokiLogger = null; +
src/apm/prometheus/prometheusClient.ts
Location:
src/apm/prometheus/prometheusClient.ts(Lines 27-27)🟡 Performance
Issue: Calling
Environment({})multiple times (inenvConfig.tsand here) may cause redundant environment variable parsing.Fix: Use the already loaded environment variables from
envVarsinstead of callingEnvironment({})again.Impact: Reduces redundant computation and improves performance
- .PROMETHEUS_LABELS_METADATA_ALLOWED_KEYS?.replaceAll(' ', '') + envVars.PROMETHEUS_LABELS_METADATA_ALLOWED_KEYS?.replaceAll(' ', '') +
src/apm/prometheus/prometheusClient.ts
Location:
src/apm/prometheus/prometheusClient.ts(Lines 322-322)🟡 Error Handling
Issue: Returning an empty string on JSON parse error in
getCustomLabelsis not informative and may hide issues with metadata formatting.Fix: Return an empty object instead to maintain consistent return types and allow for better error handling upstream.
Impact: Improves error handling consistency
- return ''; + return {}; +
src/apm/index.ts
Location:
src/apm/index.ts(Lines 3-3)🟡 Compatibility
Issue: Direct access to
process.envmay not work in all environments (e.g., Cloudflare Workers) and could cause runtime errors.Fix: Add a check for
processandprocess.envexistence before accessing them.Impact: Improves compatibility across different runtime environments
- if (process && process.env.logger === 'loki') { + if (typeof process !== 'undefined' && process.env && process.env.logger === 'loki') { +
| requiredEnvVars.forEach((varName) => { | ||
| if (!env[varName]) { | ||
| console.error(`Missing required environment variable: ${varName}`); | ||
| process.exit(1); |
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.
🔴 Security & Stability
Issue: Using process.exit(1) in library code can cause the entire application to crash abruptly without proper cleanup. This is especially problematic in serverless environments.
Fix: Throw a specific error that can be caught and handled by the application's error handling mechanism, allowing for graceful degradation.
Impact: Improves application stability and allows for better error handling
| process.exit(1); | |
| throw new Error(`Missing required environment variable: ${varName}`); | |
| requiredEnvVars.forEach((varName) => { | ||
| if (!env[varName]) { | ||
| console.error(`Missing required environment variable: ${varName}`); | ||
| process.exit(1); |
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.
🔴 Security & Stability
Issue: Using process.exit(1) in library code can cause the entire application to crash abruptly without proper cleanup. This is especially problematic in serverless environments.
Fix: Throw a specific error that can be caught and handled by the application's error handling mechanism, allowing for graceful degradation.
Impact: Improves application stability and allows for better error handling
| process.exit(1); | |
| throw new Error(`Missing required environment variable: ${varName}`); | |
|
✅ Reviewed the changes: Review of APM integration for Prometheus and Winston/Loki |
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.
🧪 PR Review is completed: Improved logger initialization with dynamic imports and type safety.
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.
🧪 PR Review is completed: Improved APM logger initialization with conditional loading based on environment configuration.
|
✅ Reviewed the changes: Review of the addition of APM_LOGGER environment variable and related type safety improvements. |
|
✅ Reviewed the changes: Review complete. Found 1 issue related to potential sensitive data exposure in error logging. |
|
✅ Reviewed the changes: Review of new Qualifire plugins and related updates. Identified issues with error logging and type safety. |
No description provided.