-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Adding temporary logging to the server #16420
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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughDetailed debug logging has been added to the Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
docs-v2/pages/api/demo-connect/utils.jsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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 (
|
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
🧹 Nitpick comments (2)
docs-v2/pages/api/demo-connect/utils.js (2)
159-160: Enhance error logging for easier troubleshooting.The error logging could be more informative to help with troubleshooting.
- console.log("Error decoding tokens:", e.message); + console.log("Error decoding tokens:", { + message: e.message, + received: requestToken, + expected: expectedToken + });
139-140: Consider a more robust approach to user-agent truncation.The current approach for truncating the user-agent is simple but could be improved.
- userAgent: req.headers["user-agent"]?.substring(0, 50) + "...", + userAgent: req.headers["user-agent"] ? + (req.headers["user-agent"].length > 50 ? + req.headers["user-agent"].substring(0, 50) + "..." : + req.headers["user-agent"]) : + "undefined",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs-v2/pages/api/demo-connect/utils.js(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Lint Code Base
| // If there's a mismatch, decode both tokens to see what's different | ||
| if (requestToken !== expectedToken) { | ||
| try { | ||
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | ||
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | ||
| console.log("Decoded tokens:", { | ||
| received: decodedReceived, | ||
| expected: decodedExpected, | ||
| }); | ||
| } catch (e) { | ||
| console.log("Error decoding tokens:", e.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.
💡 Verification agent
🧩 Analysis chain
Good approach for diagnosing token mismatches.
The approach of decoding tokens when they don't match provides valuable debugging information and includes proper error handling. The truncation of user-agent also shows good attention to log size management.
Since this is labeled as "temporary logging" in the PR title, please consider adding a TODO comment indicating when these logs should be removed, or implementing a more permanent solution with proper log levels:
🏁 Script executed:
#!/bin/bash
# Check if there are any TODO comments about removing logs
grep -n "TODO.*remov.*log" docs-v2/pages/api/demo-connect/utils.js || echo "No removal plan found for temporary logs"Length of output: 159
Add a removal plan for temporary debug logs
I didn’t find any TODO or similar comment indicating when to remove these temporary logs. Since this PR is explicitly adding diagnostic logging, please:
- Add a
TODO(orFIXME) comment in docs-v2/pages/api/demo-connect/utils.js noting when or under what condition these logs should be removed. - Or replace the
console.logcalls with a proper logger at a debug level so they can be toggled off in production.
Example:
// If there's a mismatch, decode both tokens to see what's different
if (requestToken !== expectedToken) {
try {
- const decodedReceived = Buffer.from(requestToken, "base64").toString();
+ // TODO: Remove or lower log level once token mismatch issue is resolved
+ const decodedReceived = Buffer.from(requestToken, "base64").toString();
const decodedExpected = Buffer.from(expectedToken, "base64").toString();
console.log("Decoded tokens:", {
received: decodedReceived,
expected: decodedExpected,
});
} catch (e) {
- console.log("Error decoding tokens:", e.message);
+ // TODO: Remove or lower log level once token mismatch issue is resolved
+ console.log("Error decoding tokens:", e.message);
}
}Let’s ensure these logs are either removed or controlled by log levels before merging.
📝 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.
| // If there's a mismatch, decode both tokens to see what's different | |
| if (requestToken !== expectedToken) { | |
| try { | |
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | |
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | |
| console.log("Decoded tokens:", { | |
| received: decodedReceived, | |
| expected: decodedExpected, | |
| }); | |
| } catch (e) { | |
| console.log("Error decoding tokens:", e.message); | |
| } | |
| } | |
| // If there's a mismatch, decode both tokens to see what's different | |
| if (requestToken !== expectedToken) { | |
| try { | |
| // TODO: Remove or lower log level once token mismatch issue is resolved | |
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | |
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | |
| console.log("Decoded tokens:", { | |
| received: decodedReceived, | |
| expected: decodedExpected, | |
| }); | |
| } catch (e) { | |
| // TODO: Remove or lower log level once token mismatch issue is resolved | |
| console.log("Error decoding tokens:", e.message); | |
| } | |
| } |
| // Debug logging to diagnose token validation issues | ||
| console.log("Request headers:", { | ||
| host: req.headers.host, | ||
| origin: req.headers.origin, | ||
| referer: req.headers.referer, | ||
| // Truncate user-agent to avoid huge logs | ||
| userAgent: req.headers["user-agent"]?.substring(0, 50) + "...", | ||
| }); | ||
|
|
||
| // Log token information | ||
| console.log("Token comparison:", { | ||
| received: requestToken, | ||
| expected: expectedToken, | ||
| matches: requestToken === expectedToken, | ||
| }); | ||
|
|
||
| // If there's a mismatch, decode both tokens to see what's different | ||
| if (requestToken !== expectedToken) { | ||
| try { | ||
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | ||
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | ||
| console.log("Decoded tokens:", { | ||
| received: decodedReceived, | ||
| expected: decodedExpected, | ||
| }); | ||
| } catch (e) { | ||
| console.log("Error decoding tokens:", e.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.
🛠️ Refactor suggestion
Consider security implications of debug logging sensitive information.
While these debug logs are valuable for diagnosing token validation issues, they contain potentially sensitive information such as request headers and tokens. Consider:
- Adding a toggle mechanism based on environment variables to enable/disable logging
- Using a proper logging framework with configurable log levels instead of
console.log - Adding a comment indicating when these logs should be removed or under what conditions they should remain active
+ // Environment-based logging control
+ const ENABLE_DEBUG_LOGGING = process.env.ENABLE_DEBUG_LOGGING === 'true';
// Debug logging to diagnose token validation issues
- console.log("Request headers:", {
- host: req.headers.host,
- origin: req.headers.origin,
- referer: req.headers.referer,
- // Truncate user-agent to avoid huge logs
- userAgent: req.headers["user-agent"]?.substring(0, 50) + "...",
- });
+ if (ENABLE_DEBUG_LOGGING) {
+ console.log("Request headers:", {
+ host: req.headers.host,
+ origin: req.headers.origin,
+ referer: req.headers.referer,
+ // Truncate user-agent to avoid huge logs
+ userAgent: req.headers["user-agent"]?.substring(0, 50) + "...",
+ });Apply similar conditional logging to the other log statements below as well.
📝 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.
| // Debug logging to diagnose token validation issues | |
| console.log("Request headers:", { | |
| host: req.headers.host, | |
| origin: req.headers.origin, | |
| referer: req.headers.referer, | |
| // Truncate user-agent to avoid huge logs | |
| userAgent: req.headers["user-agent"]?.substring(0, 50) + "...", | |
| }); | |
| // Log token information | |
| console.log("Token comparison:", { | |
| received: requestToken, | |
| expected: expectedToken, | |
| matches: requestToken === expectedToken, | |
| }); | |
| // If there's a mismatch, decode both tokens to see what's different | |
| if (requestToken !== expectedToken) { | |
| try { | |
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | |
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | |
| console.log("Decoded tokens:", { | |
| received: decodedReceived, | |
| expected: decodedExpected, | |
| }); | |
| } catch (e) { | |
| console.log("Error decoding tokens:", e.message); | |
| } | |
| } | |
| // Environment-based logging control | |
| const ENABLE_DEBUG_LOGGING = process.env.ENABLE_DEBUG_LOGGING === 'true'; | |
| // Debug logging to diagnose token validation issues | |
| if (ENABLE_DEBUG_LOGGING) { | |
| console.log("Request headers:", { | |
| host: req.headers.host, | |
| origin: req.headers.origin, | |
| referer: req.headers.referer, | |
| // Truncate user-agent to avoid huge logs | |
| userAgent: req.headers["user-agent"]?.substring(0, 50) + "...", | |
| }); | |
| } | |
| // Log token information | |
| if (ENABLE_DEBUG_LOGGING) { | |
| console.log("Token comparison:", { | |
| received: requestToken, | |
| expected: expectedToken, | |
| matches: requestToken === expectedToken, | |
| }); | |
| } | |
| // If there's a mismatch, decode both tokens to see what's different | |
| if (requestToken !== expectedToken) { | |
| try { | |
| const decodedReceived = Buffer.from(requestToken, "base64").toString(); | |
| const decodedExpected = Buffer.from(expectedToken, "base64").toString(); | |
| if (ENABLE_DEBUG_LOGGING) { | |
| console.log("Decoded tokens:", { | |
| received: decodedReceived, | |
| expected: decodedExpected, | |
| }); | |
| } | |
| } catch (e) { | |
| if (ENABLE_DEBUG_LOGGING) { | |
| console.log("Error decoding tokens:", e.message); | |
| } | |
| } | |
| } |
WHY
Summary by CodeRabbit