Skip to content

🧹 [Code Health] Use structured logger in Relay Server#30

Open
anusornc wants to merge 1 commit into
mainfrom
code-health/relay-logger-16151916548099373614
Open

🧹 [Code Health] Use structured logger in Relay Server#30
anusornc wants to merge 1 commit into
mainfrom
code-health/relay-logger-16151916548099373614

Conversation

@anusornc

@anusornc anusornc commented Jun 9, 2026

Copy link
Copy Markdown
Owner

🎯 What: The code health issue addressed was using console.log and console.error directly inside src/relay/server.ts. These were replaced with the centralized relayLogger defined in src/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 run and npm run build continue to succeed with no regressions, and that relayLogger is 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

…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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/relay/server.ts
}
} catch (err) {
console.error('[Relay] Invalid message:', err);
relayLogger.error('Invalid message format', { error: err });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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,
});

Comment thread src/relay/server.ts

socket.on('error', (err) => {
console.error('[Relay] Socket error:', err);
relayLogger.error('Socket error', { error: err });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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,
        });

Comment thread src/relay/server.ts
});

relay.start().catch(console.error);
relay.start().catch((err: any) => relayLogger.error('Failed to start server', { error: err }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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,
    })
  );

Comment thread src/relay/server.ts

const finish = () => {
console.log(`
relayLogger.info(`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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'
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant