Skip to content

feat: add structured logging to the intents WebSocket gateway - #167

Open
Paranoa-dev wants to merge 2 commits into
stellar-vortex-protocol:mainfrom
Paranoa-dev:feature/ws-structured-logging
Open

feat: add structured logging to the intents WebSocket gateway#167
Paranoa-dev wants to merge 2 commits into
stellar-vortex-protocol:mainfrom
Paranoa-dev:feature/ws-structured-logging

Conversation

@Paranoa-dev

Copy link
Copy Markdown

Add Structured Logging for WebSocket Events

Summary

This PR adds structured logging to IntentsGateway using the shared winston logger from src/common/logger.ts, providing operators with visibility into WebSocket activity that was previously silent.

Problem

The WebSocket gateway had zero logging — connects, disconnects, and broadcasts happened silently. Unlike HTTP requests (logged via LoggingInterceptor), there was no way to observe WS activity in production logs.

Changes

src/intents/intents.gateway.ts

  • Imported the shared logger from src/common/logger.ts
  • Connection logging: Logs ws client connected (subscribers=N) on each new connection, showing the current subscriber count
  • Disconnection logging: Logs ws client disconnected (subscribers=N) on each disconnect
  • Broadcast logging: Logs ws broadcast type=<eventType> subscribers=N at debug level for every broadcast — captures event type only (not payload) to avoid log volume blowup
  • Heartbeat logging: Logs ws heartbeat started on gateway construction, and ws heartbeat terminated dead client (subscribers=N) when a dead client is cleaned up
  • Added getSubscriberCount(): Exposes the raw subscriber count (separate from the existing getAliveCount() which only counts clients that responded to the last ping)

src/intents/intents.gateway.spec.ts

Added a new IntentsGateway logging test suite with 5 tests verifying:

  • Heartbeat started is logged on construction
  • Connection includes subscriber count
  • Disconnection includes subscriber count
  • Broadcast logs event type without payload data
  • Dead client termination logs subscriber count

Log Format

All logs follow the existing winston format: ISO_TIMESTAMP [level] message

2026-07-28T10:36:18.504Z [info] ws heartbeat started
2026-07-28T10:36:19.011Z [info] ws client connected (subscribers=1)
2026-07-28T10:36:19.511Z [debug] ws broadcast type=intent_created subscribers=1
2026-07-28T10:36:20.352Z [info] ws client disconnected (subscribers=0)
2026-07-28T10:36:50.000Z [debug] ws heartbeat terminated dead client (subscribers=0)

Design Decisions

  • Event type only, no payload: Broadcast logs include the event type (e.g., intent_created) but not the full payload, to prevent log volume blowup with large intent objects
  • Debug level for broadcasts: Broadcast and heartbeat termination logs use debug level (only visible in non-production), while connect/disconnect use info level for production visibility
  • Subscriber count included: Every log message includes the current subscriber count for context

Test Results

Unit tests:  29 passed (4 suites)
E2e tests:   23 passed (5 suites)
Total:       52 tests passing

Checklist

  • Uses shared winston logger from src/common/logger.ts
  • Logs connection count changes
  • Logs broadcast event types (not payloads)
  • Logs heartbeat lifecycle events
  • Unit tests for all logging behavior
  • npm run lint passes
  • npm run typecheck passes
  • npm test passes
  • npm run test:e2e passes

Closes #82

- Add periodic ping/pong heartbeat to IntentsGateway using the standard
  ws library pattern
- Track alive status per client with a WeakMap
- Every 30s, mark all clients as 'not alive', send ping; clients that
  respond with pong are marked alive again; those that don't are
  terminated and removed from the subscriber set
- Implement OnModuleDestroy to clean up the heartbeat interval
- Add unit tests for heartbeat behavior (alive marking, pong response,
  dead client termination, interval cleanup)
- Fix e2e config for pre-existing test environment issues

Closes stellar-vortex-protocol#81
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Paranoa-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add structured logging for WebSocket connect/disconnect/broadcast events

1 participant