DEV Community

Netanel Avraham
Netanel Avraham

Posted on • Edited on

3 2 2 2 2

[Open Source] Simplify Metrics Reporting in NestJS with a Zero-Dependency-Injection Global Reporter

Hey everyone! 👋

I'd like to share an open-source package I recently developed called nestjs-metrics-reporter. It's designed to make metrics reporting in NestJS as simple and seamless as possible.

Why Did I Create This?

When using other metrics libraries, I found that the dependency injection setup and boilerplate often got in the way more than they helped. Because of this, I wrote a zero-dependency-injection alternative to make reporting metrics from anywhere in your codebase easier.

I wrote about the motivation and technical details in more depth in my Medium article Avoid Prometheus Mess in NestJS

Key Features

  • No Dependency Injection – Global static ReporterService for clean, portable code.
  • Effortless Integration – Zero-setup, start tracking metrics instantly.
  • Support for Pushgateway – Push batch job metrics effortlessly.
  • Designed for Simplicity – Spend time coding, rather than dealing with complex configurations.

How It Works

With a minimal setup in your AppModule, you'll start reporting metrics like counters, gauges, histograms, and summaries in no time:

1. Install the package:

npm install nestjs-metrics-reporter
Enter fullscreen mode Exit fullscreen mode

2. Configure the module:

ReporterModule.forRoot({
   defaultMetricsEnabled: true,
   defaultLabels: {
     app: 'my-app',
   },
}),
Enter fullscreen mode Exit fullscreen mode

3. Report metrics anywhere in your application:

ReporterService.gauge('active_users', 42, { region: 'us-east-1' });
Enter fullscreen mode Exit fullscreen mode

I'd be happy to hear your feedback! Feel free to dive in, open issues, or send PRs my way.

👉 GitHub Repo: nestjs-metrics-reporter

👉 NPM Package: nestjs-metrics-reporter

If you find this helpful, please consider starring ⭐ the repo on GitHub and using the package in your projects. Your feedback will help make it even better.

Top comments (1)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more