Skip to content

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

Merged
james2177 merged 2 commits into
stellar-vortex-protocol:mainfrom
Paranoa-dev:feature/ws-structured-logging
Jul 30, 2026
Merged

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

Conversation

@Paranoa-dev

Copy link
Copy Markdown
Contributor

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

@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

@james2177
james2177 merged commit f94f04c into stellar-vortex-protocol:main Jul 30, 2026
0 of 3 checks passed
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

2 participants