Skip to content

feat: add circuit breaker, error handler, Prometheus metrics, and Dockerfile improvements - #325

Merged
abayomicornelius merged 2 commits into
Heliobond:mainfrom
Odkinggjnr:feat/production-readiness
Jul 30, 2026
Merged

feat: add circuit breaker, error handler, Prometheus metrics, and Dockerfile improvements#325
abayomicornelius merged 2 commits into
Heliobond:mainfrom
Odkinggjnr:feat/production-readiness

Conversation

@Odkinggjnr

Copy link
Copy Markdown
Contributor

Description

This PR implements four production-readiness improvements for the Heliobond backend:

1. Circuit Breaker for Stellar RPC Calls (Closes #200)

  • Added CIRCUIT_BREAKER_THRESHOLD and CIRCUIT_BREAKER_COOLDOWN_MS configurable environment variables (with backward-compatible fallbacks to existing RPC_BREAKER_* vars)
  • Replaced console.warn with structured logger.warn for circuit state transitions (CLOSED → OPEN → HALF_OPEN), including metadata for observability
  • Updated .env.example with new circuit breaker env var documentation
  • Added tests verifying logger integration and configurable thresholds

2. Express Error-Handling Middleware (Closes #199)

  • Updated error handler to use structured logger.error for server-side logging instead of console.error
  • Changed error code to INTERNAL_ERROR (uppercase) matching the issue's acceptance criteria format: {"error":{"code":"INTERNAL_ERROR","message":"..."}}
  • Stack traces are logged server-side but never exposed to clients
  • Added test for async route handler error catching (Express 5 compatibility)
  • Updated existing tests to validate the new error response format

3. Prometheus Metrics Endpoint (Closes #201)

  • Installed prom-client and created src/lib/prometheus.ts with metrics registry
  • Added /metrics endpoint returning Prometheus text format
  • HTTP metrics: http_request_duration_seconds histogram and http_requests_total counter (labeled by method, route, status_code)
  • Stellar RPC metrics: stellar_rpc_call_duration_seconds histogram and stellar_rpc_calls_total counter (labeled by operation, result)
  • Cron metrics: cron_job_duration_seconds histogram and cron_job_runs_total counter (labeled by job, result)
  • Transaction metrics: stellar_tx_submissions_total counter and circuit_breaker_state gauge
  • Added prometheusMiddleware for automatic HTTP request instrumentation
  • Comprehensive test suite for the /metrics endpoint

4. Dockerfile for Containerized Deployment (Closes #198)

  • Updated to Node.js 20 alpine (per README specification)
  • Fixed production port to 3001 (matching config.PORT default)
  • Added non-root user (appuser) for security best practice
  • Multi-stage build (build + production) for optimized image size
  • Updated docker-compose.yml with required env vars (ADMIN_SECRET_KEY, PROJECT_REGISTRY_CONTRACT_ID)
  • Expanded .dockerignore to exclude test files, docs, and dev configs
  • Added tests for multi-stage build, port 3001, and Node.js 20 base image

Type of change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update

Testing checklist

  • Tests pass locally
  • Added new tests (if applicable)
  • Code follows project conventions

Related issues

Closes #198, Closes #199, Closes #200, Closes #201

Notes

  • The bun.lock file may need to be regenerated with bun install to include the new prom-client dependency before CI passes with --frozen-lockfile
  • All env var additions are backward-compatible with sensible defaults

Odkinggjnr and others added 2 commits July 29, 2026 23:15
…kerfile improvements

- Circuit breaker (Heliobond#200): Add CIRCUIT_BREAKER_THRESHOLD and CIRCUIT_BREAKER_COOLDOWN_MS
  env vars, use structured logger for state transitions instead of console.warn
- Error handler (Heliobond#199): Use structured logger for server-side error logging, return
  INTERNAL_ERROR code in JSON response, verify async error handling with Express 5
- Prometheus metrics (Heliobond#201): Add prom-client with /metrics endpoint exposing HTTP
  request duration/count, Stellar RPC call duration/success/failure, cron job
  duration/success/failure, and transaction submission metrics
- Dockerfile (Heliobond#198): Use Node.js 20 alpine, fix port to 3001, add non-root user,
  update docker-compose with required env vars, expand .dockerignore

Closes Heliobond#198, Closes Heliobond#199, Closes Heliobond#200, Closes Heliobond#201
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Odkinggjnr 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

@abayomicornelius
abayomicornelius merged commit 3e76089 into Heliobond:main Jul 30, 2026
0 of 2 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

2 participants