Overview & Background
As FlowFi scales to support real-time high-throughput streaming events, infrastructure visibility is critical. The backend currently uses Winston for structured logging, but lacks time-series APM metrics and distributed tracing. Production monitoring requires standard Prometheus metrics to track indexer synchronization lag, RPC latency, SSE client pool saturation, and database connection pool utilization.
Detailed Problem Statement
- Invisible Indexer Lag:
- Operators cannot monitor how many ledgers the indexer is lagging behind the live Stellar ledger sequence.
- No RPC Pool Health Visibility:
- Failovers and circuit breaker trips across multi-RPC nodes are not exposed as trackable metrics.
- SSE Connection Saturation:
- Memory and file descriptor exhaustion from long-lived SSE connections cannot be anticipated without real-time gauges.
Technical Specification & Architecture
1. Prometheus Metrics Instrumentation (prom-client)
Implement backend/src/lib/metrics.ts exporting:
flowfi_indexer_current_ledger: Gauge of last indexed ledger.
flowfi_indexer_network_ledger: Gauge of current network ledger sequence.
flowfi_indexer_lag_ledgers: Computed gauge (network - current).
flowfi_sse_active_connections: Gauge of connected SSE clients by topic/user.
flowfi_rpc_request_duration_seconds: Histogram of Stellar RPC requests partitioned by method (simulateTransaction, sendTransaction, getEvents).
flowfi_db_query_duration_seconds: Histogram of Prisma query durations.
flowfi_http_requests_total: Counter of API requests by status code and route.
2. Metrics Endpoint
- Expose
GET /metrics in backend/src/app.ts.
- Restrict to internal cluster network or protect via Prometheus bearer token.
3. OpenTelemetry Tracing Integration
- Initialize
@opentelemetry/sdk-node in backend/src/index.ts to trace HTTP request lifecycles through controllers, database operations, and outbound RPC calls.
Target Files
backend/src/lib/metrics.ts
backend/src/routes/health.routes.ts
backend/src/services/indexer.service.ts
backend/src/services/sse.service.ts
backend/src/services/sorobanService.ts
Acceptance Criteria
Overview & Background
As FlowFi scales to support real-time high-throughput streaming events, infrastructure visibility is critical. The backend currently uses Winston for structured logging, but lacks time-series APM metrics and distributed tracing. Production monitoring requires standard Prometheus metrics to track indexer synchronization lag, RPC latency, SSE client pool saturation, and database connection pool utilization.
Detailed Problem Statement
Technical Specification & Architecture
1. Prometheus Metrics Instrumentation (
prom-client)Implement
backend/src/lib/metrics.tsexporting:flowfi_indexer_current_ledger: Gauge of last indexed ledger.flowfi_indexer_network_ledger: Gauge of current network ledger sequence.flowfi_indexer_lag_ledgers: Computed gauge (network - current).flowfi_sse_active_connections: Gauge of connected SSE clients by topic/user.flowfi_rpc_request_duration_seconds: Histogram of Stellar RPC requests partitioned by method (simulateTransaction,sendTransaction,getEvents).flowfi_db_query_duration_seconds: Histogram of Prisma query durations.flowfi_http_requests_total: Counter of API requests by status code and route.2. Metrics Endpoint
GET /metricsinbackend/src/app.ts.3. OpenTelemetry Tracing Integration
@opentelemetry/sdk-nodeinbackend/src/index.tsto trace HTTP request lifecycles through controllers, database operations, and outbound RPC calls.Target Files
backend/src/lib/metrics.tsbackend/src/routes/health.routes.tsbackend/src/services/indexer.service.tsbackend/src/services/sse.service.tsbackend/src/services/sorobanService.tsAcceptance Criteria
GET /metricsoutputs standard Prometheus scrape format.backend/docs/observability/grafana-dashboard.json.