feat: Platform Hardening & Observability: Distributed Tracing, Recurring Billing, WebSocket Monitoring, Payout Security - #1625
Merged
davedumto merged 1 commit intoSep 24, 2026
Conversation
…rring billing, WebSocket monitoring, payout security
|
@Just-Bamford is attempting to deploy a commit to the chibuikemmichaelilonze's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Just-Bamford 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Summary
This PR implements four critical platform improvements addressing observability, retention, infrastructure resilience, and financial security.
Closes #1420
Closes #1421
Closes #1422
Closes #1423
Issues Addressed
1. Distributed Tracing Across Service Boundaries
lib/tracing/trace-context.ts- Core trace context management with per-request unique IDslib/tracing/logger.ts- Structured JSON logging with automatic trace context injectionmiddleware.ts- Global middleware generating/extracting trace IDs for all requestslib/tracing/api-route-wrapper.ts- Higher-order route handler wrapper with automatic tracinglib/tracing/fetch-tracer.ts- Outbound request wrapper for Mux/Horizon/external API callslib/tracing/db-tracer.ts- Database query tracer with SQL comment injectionTRACING_ARCHITECTURE.md- Complete architecture documentationlib/mux/server.ts- All Mux API calls now log with trace contextlib/stellar/horizon.ts&lib/stellar/payments.ts- All Horizon/Stellar calls tracedapp/api/tips/send/route.ts- End-to-end example showing full trace flowx-request-idflowing through all services; engineers can grep by trace ID to follow entire request lifecycle across all systems2. Recurring-Billing Simulation: Expiry Alerts & One-Click Renewal
lib/subscriptions/expiry-notifier.ts- Expiry notification logic with configurable thresholdsapp/api/routes-f/cron-subscription-expiry-alerts/route.ts- Cron job sending expiry alertsapp/api/routes-f/subscription-renew/route.ts- One-click renewal retrieval (pre-populated intent)app/api/routes-f/subscription-renew-confirm/route.ts- Renewal confirmation with new paymentapp/api/routes-f/subscription-renew/__tests__/subscription-renewal.test.ts- Comprehensive testsapp/api/routes-f/subscriptions/route.ts- Updated schema withexpiry_alert_sent_atandrenewal_countAUTOPAY_ARCHITECTURE_DECISION.md- Phased autopay roadmap (Phase 1: this PR, Phase 2: custodial balance, Phase 3: Soroban smart contract)3. WebSocket/SSE Connection Monitoring & Per-Instance Capacity Limits
lib/realtime/connection-manager.ts- Per-instance connection tracking with capacity enforcement, three shedding strategies (reject_new, shed_oldest, shed_least_active), priority-based sheddinglib/realtime/metrics-exporter.ts- Prometheus + JSON metrics export, alert sink for external integrations (Datadog, PagerDuty)lib/realtime/websocket-server-example.ts- Reference WebSocket server integration showing lifecycle hooks, metrics export, graceful shutdownlib/realtime/__tests__/connection-manager.test.ts- 30+ tests covering capacity enforcement, shedding strategies, graceful shutdown, load scenariosREALTIME_CONNECTION_MONITORING_SPEC.md- Complete specification with deployment checklist, alerting configuration, load testing strategy4. Payout-Address Verification to Prevent Silent Redirection
lib/payouts/payout-address-verifier.ts- Time-locked changes with state machine (pending → verified → active), out-of-band notifications, test-payment confirmation, rate limiting, cancellation supportapp/api/routes-f/payout-address-change/route.ts- Initiate time-locked change (authenticated)app/api/routes-f/payout-address-cancel/route.ts- Cancel unverified changes (supports no-auth email links + authenticated cancellation)app/api/routes-f/payout-address-verify-payment/route.ts- Confirm test payment (wallet ownership verification)app/api/routes-f/cron-verify-pending-payout-changes/route.ts- Auto-verify after cooldown elapsesapp/api/routes-f/payout-address-change/__tests__/payout-verification.test.ts- 40+ tests covering cooldown enforcement, cancellation, test-payment flow, rate limitingPAYOUT_ADDRESS_SECURITY_SPEC.md- Security architecture with attack scenarios, API specs, email templates, deployment checklistTesting
All implementations include comprehensive test coverage:
app/api/tips/send/route.tsFiles Changed
Core Implementation
lib/tracing/- Distributed tracing (5 files)lib/subscriptions/- Expiry notification system (1 file)lib/payouts/- Payout verification (1 file)lib/realtime/- WebSocket monitoring (4 files + 1 test file)API Endpoints
app/api/routes-f/cron-subscription-expiry-alerts/- Expiry alert cronapp/api/routes-f/subscription-renew/- One-click renewal (1 file + 1 test file)app/api/routes-f/subscription-renew-confirm/- Renewal confirmationapp/api/routes-f/payout-address-change/- Initiate payout change (1 file + 1 test file)app/api/routes-f/payout-address-cancel/- Cancel payout changeapp/api/routes-f/payout-address-verify-payment/- Test-payment verificationapp/api/routes-f/cron-verify-pending-payout-changes/- Payout change verification cronapp/api/tips/send/- End-to-end tracing exampleDocumentation
TRACING_ARCHITECTURE.md- Distributed tracing design, integration guide, debugging workflowAUTOPAY_ARCHITECTURE_DECISION.md- Recurring billing roadmap (Phase 1/2/3) with tradeoffsREALTIME_CONNECTION_MONITORING_SPEC.md- WebSocket monitoring architecture, deployment checklistPAYOUT_ADDRESS_SECURITY_SPEC.md- Payout security design, attack scenarios, integration guideModified Files
middleware.ts- Global trace ID generation and propagationlib/mux/server.ts- Instrumented with structured logginglib/stellar/horizon.ts&lib/stellar/payments.ts- Instrumented with trace contextapp/api/routes-f/subscriptions/route.ts- Updated schema for expiry tracking