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

πŸš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsβ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post β†’

Top comments (1)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay