🧹 [Code Health] Use structured logger in Relay Server#30
Conversation
…sole.log and console.error calls with the centralized `relayLogger` imported from `src/utils/logger.js`. Errors are correctly passed as context payload to preserve stack traces. Removes redundant '[Relay]' string prefixes. Co-authored-by: anusornc <11565019+anusornc@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request replaces standard console logging with structured logging using relayLogger in src/relay/server.ts. The feedback highlights that passing raw Error objects directly to the structured logger will cause them to serialize as empty objects, losing critical error details and stack traces. Additionally, logging a multi-line ASCII art banner using a structured logger will result in escaped newline characters, making it hard to read in log aggregators; this should be replaced with a clean, single-line message with structured metadata.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| } | ||
| } catch (err) { | ||
| console.error('[Relay] Invalid message:', err); | ||
| relayLogger.error('Invalid message format', { error: err }); |
There was a problem hiding this comment.
In JavaScript/TypeScript, Error objects do not have enumerable properties (like message and stack). When passed directly to JSON.stringify (which relayLogger uses under the hood), they serialize to an empty object {}. This means the actual error details and stack trace will be completely lost in your structured logs.
To preserve this critical diagnostic information, extract the error's message and stack trace explicitly.
| relayLogger.error('Invalid message format', { error: err }); | |
| relayLogger.error('Invalid message format', { | |
| error: err instanceof Error ? err.message : String(err), | |
| stack: err instanceof Error ? err.stack : undefined, | |
| }); |
|
|
||
| socket.on('error', (err) => { | ||
| console.error('[Relay] Socket error:', err); | ||
| relayLogger.error('Socket error', { error: err }); |
There was a problem hiding this comment.
In JavaScript/TypeScript, Error objects do not have enumerable properties (like message and stack). When passed directly to JSON.stringify (which relayLogger uses under the hood), they serialize to an empty object {}. This means the actual error details and stack trace will be completely lost in your structured logs.
To preserve this critical diagnostic information, extract the error's message and stack trace explicitly.
relayLogger.error('Socket error', {
error: err instanceof Error ? err.message : String(err),
stack: err instanceof Error ? err.stack : undefined,
});| }); | ||
|
|
||
| relay.start().catch(console.error); | ||
| relay.start().catch((err: any) => relayLogger.error('Failed to start server', { error: err })); |
There was a problem hiding this comment.
In JavaScript/TypeScript, Error objects do not have enumerable properties (like message and stack). When passed directly to JSON.stringify (which relayLogger uses under the hood), they serialize to an empty object {}. This means the actual error details and stack trace will be completely lost in your structured logs.
To preserve this critical diagnostic information, extract the error's message and stack trace explicitly.
relay.start().catch((err: any) =>
relayLogger.error('Failed to start server', {
error: err instanceof Error ? err.message : String(err),
stack: err instanceof Error ? err.stack : undefined,
})
);|
|
||
| const finish = () => { | ||
| console.log(` | ||
| relayLogger.info(` |
There was a problem hiding this comment.
Logging a multi-line ASCII art banner using a structured JSON logger (relayLogger.info) will result in a single log entry with escaped newline characters (\n), making it extremely difficult to read in log aggregation tools (e.g., Kibana, Datadog, or CloudWatch).
Since relayLogger is a structured logger, it is highly recommended to log a clean, single-line message and pass the server configuration details as structured metadata instead. For example:
relayLogger.info('DAP Relay Server started successfully', {
version: '1.0.0',
host: this.config.host,
port: this._boundPort,
wsUrl: `ws://${this.config.host}:${this._boundPort}/ws`,
apiKeys: this.config.apiKeys.length > 0 ? this.config.apiKeys : 'open',
heartbeatIntervalMs: this.config.heartbeatIntervalMs,
tls: this.config.enableTls ? 'enabled' : 'disabled'
});
🎯 What: The code health issue addressed was using
console.logandconsole.errordirectly insidesrc/relay/server.ts. These were replaced with the centralizedrelayLoggerdefined insrc/utils/logger.ts. Error logging correctly wraps exception objects inside the structured logging metadata payload.💡 Why: This improves maintainability and readability by keeping structured logs uniform across the protocol, making logs easier to parse in monitoring tools (like Prometheus or external observability stacks). It removes hardcoded
[Relay]string prefixes that exist elsewhere, delegating formatting logic entirely to the logger itself.✅ Verification: Verified that
npx vitest runandnpm run buildcontinue to succeed with no regressions, and thatrelayLoggeris correctly integrated. The code review confirmed all changes were applied safely.✨ Result: Improved maintainability, consistency, and better observability of the RelayServer code.
PR created automatically by Jules for task 16151916548099373614 started by @anusornc