-
Notifications
You must be signed in to change notification settings - Fork 22
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
added timestamps to the API consumption logs #3732
Conversation
📝 WalkthroughWalkthroughThe changes introduce a new logging function, Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## staging #3732 +/- ##
===========================================
- Coverage 11.69% 11.69% -0.01%
===========================================
Files 110 110
Lines 14847 14848 +1
Branches 274 274
===========================================
Hits 1737 1737
- Misses 13110 13111 +1
|
Device registry changes in this PR available for preview here |
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
src/device-registry/utils/log.js (1)
Line range hint
1-43
: Consider centralizing logging configurationTo ensure consistency across the AirQo platform:
- Consider moving logging configuration to a shared utility
- Define standard timestamp formats in a configuration file
- Implement structured logging for better parsing in production
This would make it easier to:
- Maintain consistent logging across all services
- Switch logging providers if needed
- Implement log aggregation and analysis
src/device-registry/utils/create-event.js (1)
2651-2652
: Consider including the error stack trace for better debugging.While the timestamp addition is good, consider including the error stack trace in the log message for better error tracking.
- logTextWithTimestamp(`API: Internal Server Error ${error.message}`); + logTextWithTimestamp(`API: Internal Server Error ${error.message}\n${error.stack}`);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- src/device-registry/utils/create-event.js (4 hunks)
- src/device-registry/utils/log.js (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
src/device-registry/utils/log.js (1)
37-43
: LGTM! Clean and well-organized exportsThe module exports are properly structured and include all logging utilities.
src/device-registry/utils/create-event.js (2)
2632-2633
: LGTM! Good error tracking enhancement.The addition of timestamp logging for failed operations will help with debugging and monitoring API consumption issues.
2642-2643
: LGTM! Good success tracking enhancement.The addition of timestamp logging for successful operations will help track API consumption patterns and performance.
const logTextWithTimestamp = (message) => { | ||
console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`); | ||
}; |
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.
Align logTextWithTimestamp with existing logging patterns
The new function differs from other logging utilities in three ways:
- Missing environment check (logs in production)
- No return value
- Inconsistent error handling
Suggested implementation:
const logTextWithTimestamp = (message) => {
- console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`);
+ if (process.env.NODE_ENV !== "production") {
+ console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`);
+ }
+ return "log deactivated in prod and stage";
};
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const logTextWithTimestamp = (message) => { | |
console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`); | |
}; | |
const logTextWithTimestamp = (message) => { | |
if (process.env.NODE_ENV !== "production") { | |
console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`); | |
} | |
return "log deactivated in prod and stage"; | |
}; |
@@ -1,3 +1,5 @@ | |||
const moment = require("moment"); |
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.
🛠️ Refactor suggestion
Consider using native Date methods instead of moment.js
For simple timestamp formatting, native JavaScript methods like new Date().toISOString()
or Intl.DateTimeFormat
could be more performant alternatives to moment.js, which is a relatively heavy library.
Example implementation:
-const moment = require("moment");
+const formatTimestamp = () => {
+ return new Intl.DateTimeFormat('en-US', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ hour: '2-digit',
+ minute: '2-digit',
+ second: '2-digit',
+ hour12: false
+ }).format(new Date()).replace(/(\d+)\/(\d+)\/(\d+)/, '$3-$1-$2');
+};
Committable suggestion was skipped due to low confidence.
Description
added timestamps to the API consumption logs
Changes Made
Testing
Affected Services
Endpoints Ready for Testing
API Documentation Updated?
Additional Notes
added timestamps to the API consumption logs
Summary by CodeRabbit
New Features
Bug Fixes