Description
src/middleware/httpMetrics.ts captures generic HTTP metrics but no domain-specific business metrics are instrumented. Operators cannot alert on webhook delivery failure rates, stream creation throughput, or indexer ingestion lag using the existing Prometheus data. Custom prom-client metrics must be added across src/routes/streams.ts, src/webhooks/service.ts, and src/indexer/service.ts.
Requirements and context
- Register the following prom-client metrics:
fluxora_streams_created_total (counter, labels: status), fluxora_webhook_deliveries_total (counter, labels: outcome), fluxora_webhook_delivery_duration_seconds (histogram), fluxora_indexer_events_ingested_total (counter), fluxora_indexer_lag_seconds (gauge)
- Instrument each metric at the appropriate callsite in source files
- Ensure metrics are de-registered cleanly between vitest test runs to avoid duplicate registration errors
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/custom-business-metrics
Implement changes
- Update/Write:
src/metrics/businessMetrics.ts — register all custom prom-client metrics
- Update/Write:
src/routes/streams.ts, src/webhooks/service.ts, src/indexer/service.ts — instrument metrics
- Write comprehensive tests:
tests/metrics/businessMetrics.test.ts
- Add documentation:
docs/observability.md — document each metric, labels, and alerting recommendations
- Include clear code comments and types
- Validate security assumptions
Test and commit
- Run tests:
pnpm test (or pnpm test:coverage)
- Cover edge cases: metric incremented on success, metric incremented on failure, histogram bucket distribution, duplicate registration guard
- Include test output and security notes
Example commit message
feat: add custom business metrics for streams, webhooks, and indexer
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
src/middleware/httpMetrics.tscaptures generic HTTP metrics but no domain-specific business metrics are instrumented. Operators cannot alert on webhook delivery failure rates, stream creation throughput, or indexer ingestion lag using the existing Prometheus data. Custom prom-client metrics must be added acrosssrc/routes/streams.ts,src/webhooks/service.ts, andsrc/indexer/service.ts.Requirements and context
fluxora_streams_created_total(counter, labels: status),fluxora_webhook_deliveries_total(counter, labels: outcome),fluxora_webhook_delivery_duration_seconds(histogram),fluxora_indexer_events_ingested_total(counter),fluxora_indexer_lag_seconds(gauge)Suggested execution
Fork the repo and create a branch
Implement changes
src/metrics/businessMetrics.ts— register all custom prom-client metricssrc/routes/streams.ts,src/webhooks/service.ts,src/indexer/service.ts— instrument metricstests/metrics/businessMetrics.test.tsdocs/observability.md— document each metric, labels, and alerting recommendationsTest and commit
pnpm test(orpnpm test:coverage)Example commit message
Guidelines