Production-Grade Observability, Logging, and Analytics Integration#110
Merged
Conversation
…s integration - Add Prometheus metrics endpoint with counters and histograms for events, failures, DLQ, cursor lag, agent loop - Instrument event listener, processing pipeline, retry system, and agent loop with actionable telemetry - Enhance logger with rotating file transports, JSON output, configurable levels, sensitive data redaction - Replace all console.* usage with structured logger methods across codebase - Add ESLint no-console rule to enforce logging best practices - Document alert thresholds and Grafana dashboard recommendations - Create reusable test factories for analytics endpoints - Expand integration coverage for /api/analytics with auth, validation, and grouped protocol tests
|
@johnsmccain 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! 🚀 |
- fix(loop): change updateAgentStatus('error') to 'degraded' (TS2345)
- fix(events): rename local updateLastProcessedLedger to persistLastProcessedLedger to resolve import conflict (TS2440)
- fix(seed): replace console.log with console.warn to satisfy no-console ESLint rule
…on expired session
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.
Summary
This PR implements comprehensive production-grade observability, structured logging, and expanded analytics integration coverage for the NeuroWealth backend.
Changes
📊 Prometheus Metrics Endpoint
New Files:
src/utils/metrics.ts- Prometheus metrics registry with counters and histogramssrc/routes/metrics.ts-/metricsendpoint for Prometheus scrapingMetrics Implemented:
events_processed_total,events_processing_duration_seconds,events_processing_rate_per_minutefailures_total,failure_ratedlq_size,dlq_retry_totalcursor_lag_ledgers,last_processed_ledgeragent_loop_heartbeat_timestamp,agent_loop_status,agent_rebalance_checks_total,agent_rebalances_triggered_total,agent_snapshot_duration_secondsdb_operation_duration_seconds,db_connections_activehttp_requests_total,http_request_duration_secondsanalytics_requests_total,analytics_request_duration_seconds🔧 Instrumentation
Modified Files:
src/stellar/events.ts- Added metrics recording for event processing, cursor lag, DB operationssrc/stellar/dlq.ts- Added DLQ size tracking on add/retry operationssrc/agent/loop.ts- Added heartbeat, status, rebalance, and snapshot metricssrc/index.ts- Added/metricsroute to Express app📝 Structured Logging
Modified File:
src/utils/logger.ts- Enhanced with:LOG_LEVELenvironment variableaddCloudLoggingAdapter()function for cloud integrationsReplaced all console. usage with structured logger methods:*
src/config/env.ts-console.log→logger.info,console.warn→logger.warnsrc/middleware/authenticate.ts-console.error→logger.errorsrc/routes/whatsapp.ts-console.error→logger.errorsrc/stellar/wallet.ts-console.log→logger.info🚦 ESLint Rules
Modified File:
eslint.config.mjs- Added'no-console': ['error', { allow: ['warn', 'error'] }]to enforce no console usage in production code📚 Documentation
New File:
docs/OBSERVABILITY.md- Comprehensive observability guide including:🧪 Analytics Integration Tests
New File:
tests/helpers/analyticsTestFactory.ts- Reusable test data factories:createTestUser(),createTestPosition(),createTestYieldSnapshots()createTestProtocolRates(),createTestSession()setupAnalyticsTestData()- Complete test data setupcleanupAnalyticsTestData()- Proper database cleanupcreateGroupedProtocolTestData()- For testing grouped protocol structurescreateValidationFailureTestData()- For validation failure scenariosModified File:
tests/integration/api/analytics.test.ts- Expanded coverage:📦 Dependencies
Modified File:
package.json- Addedprom-clientdependency for Prometheus metricspackage-lock.json- Updated with new dependencyTesting
All existing tests pass with the new changes. The expanded analytics integration tests cover:
Configuration
Environment Variables
Cloud Logging (Optional)
Examples provided in
docs/OBSERVABILITY.mdfor:Deployment
/metricsendpoint is automatically available athttp://your-server:port/metricsdocs/OBSERVABILITY.mdBreaking Changes
None. This is a pure addition with no breaking changes to existing functionality.
Checklist
Close #94
Close #95
Close #96
Close #97