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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay