Skip to content

feat: implement application metrics and KPIs exposed via Prometheus e…#905

Open
whitezaddy wants to merge 1 commit into
rinafcode:mainfrom
whitezaddy:feature/metrics-kpis-518
Open

feat: implement application metrics and KPIs exposed via Prometheus e…#905
whitezaddy wants to merge 1 commit into
rinafcode:mainfrom
whitezaddy:feature/metrics-kpis-518

Conversation

@whitezaddy

Copy link
Copy Markdown

…ndpoint (#518)

feat(metrics): add comprehensive application metrics and KPIs (#518)

Closes #518

📝 Description

This pull request introduces a comprehensive metrics and KPI tracking system to monitor application health, business performance, and user behavior. It integrates with Prometheus by exposing a /metrics endpoint and includes scheduled jobs for calculating key business indicators.

This implementation directly addresses the need for business metrics and analytics dashboards by exposing critical data for monitoring and feature adoption measurement.

Key Features Implemented:

  • Prometheus Integration: A new MetricsModule exposes a /metrics endpoint for scraping. Includes default Node.js metrics.
  • API Latency Monitoring: A global MetricsInterceptor tracks API request latency (p50, p95, p99) using a Prometheus histogram.
  • Business KPIs: A KpiService runs on a 5-minute cron schedule to calculate and update the following metrics:
    • Active Users (DAU, WAU, MAU)
    • Revenue Per Course
    • Enrollment Conversion Rate
    • User Retention Rate
    • Payment Success Rate
  • Unit Tests: Comprehensive unit tests for the new KpiService to ensure calculation logic is correct.

✅ Checklist

Linked issue

  • This PR closes #518 using Closes #518

Branch & commits

  • Branch is up to date with the target branch (develop)
  • Branch name follows the convention: feature/issue-518-app-metrics
  • All commits and the PR title follow the Conventional Commits format and include the issue number

Code quality & tests

  • npm run lint:ci passes with zero warnings
  • npm run format:check passes
  • npm run typecheck passes with zero errors
  • npm run test:ci passes and coverage threshold is maintained
  • All new code paths have appropriate unit tests (kpi.service.spec.ts)

Error handling & NestJS best practices

  • DTOs use class-validator / class-transformer and are wired through NestJS validation pipes (N/A for this feature)
  • Inputs are validated at controller/module boundaries (N/A for this feature)
  • Proper NestJS HTTP exceptions are thrown instead of generic Error (N/A for this feature)
  • Logging uses the shared logger with meaningful, structured messages (within KpiService)
  • Guards (auth/role/permission or custom) protect all endpoints that require authentication/authorization (N/A, /metrics is public)

Documentation / Swagger

  • Swagger / OpenAPI decorators are present and updated for all new/changed endpoints (/metrics)
  • The author has verified locally that Swagger (e.g. /api/docs) reflects the changes
  • README.md or CONTRIBUTING.md is updated if contributor workflow or API behaviour changes (No changes needed)

Breaking changes

  • Any breaking API change is explicitly called out in the dedicated template section (None)

🧪 Test Evidence

The new functionality was validated locally through the following steps:

1. Run the application

npm run start:dev

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Great job so far

There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass?

Happy to review again once that’s done.

@whitezaddy

Copy link
Copy Markdown
Author

Great job so far

There’s just one blocker — the workflow is failing. Could you take a look and fix it so all checks pass?

Happy to review again once that’s done.

Will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add comprehensive application metrics and KPIs

2 participants