<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Netanel Avraham</title>
    <description>The latest articles on DEV Community by Netanel Avraham (@netanelavr).</description>
    <link>https://dev.to/netanelavr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2564921%2Fe8deef61-9328-4741-a24a-26539089dbe0.png</url>
      <title>DEV Community: Netanel Avraham</title>
      <link>https://dev.to/netanelavr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/netanelavr"/>
    <language>en</language>
    <item>
      <title>[Open Source] Simplify Metrics Reporting in NestJS with a Zero-Dependency-Injection Global Reporter</title>
      <dc:creator>Netanel Avraham</dc:creator>
      <pubDate>Fri, 13 Dec 2024 06:39:18 +0000</pubDate>
      <link>https://dev.to/netanelavr/open-source-simplify-metrics-reporting-in-nestjs-with-a-zero-dependency-injection-global-reporter-36pa</link>
      <guid>https://dev.to/netanelavr/open-source-simplify-metrics-reporting-in-nestjs-with-a-zero-dependency-injection-global-reporter-36pa</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hey everyone!&lt;/strong&gt; 👋&lt;/p&gt;

&lt;p&gt;I'd like to share an open-source package I recently developed called &lt;a href="https://github.com/netanelavr/nestjs-metrics-reporter" rel="noopener noreferrer"&gt;nestjs-metrics-reporter&lt;/a&gt;. It's designed to make metrics reporting in &lt;strong&gt;NestJS&lt;/strong&gt; as simple and seamless as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Did I Create This?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;strong&gt;zero-dependency-injection&lt;/strong&gt; alternative to make reporting metrics from anywhere in your codebase easier.&lt;/p&gt;

&lt;p&gt;I wrote about the motivation and technical details in more depth in my Medium article &lt;a href="https://medium.com/elementor-engineers/avoid-prometheus-mess-in-nestjs-1ea368e3e21e" rel="noopener noreferrer"&gt;Avoid Prometheus Mess in NestJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With a minimal setup in your AppModule, you'll start reporting metrics like counters, gauges, histograms, and summaries in no time:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Install the package:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install nestjs-metrics-reporter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2. Configure the module:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReporterModule.forRoot({
   defaultMetricsEnabled: true,
   defaultLabels: {
     app: 'my-app',
   },
}),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Report metrics anywhere in your application:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ReporterService.gauge('active_users', 42, { region: 'us-east-1' });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I'd be happy to hear your feedback! Feel free to dive in, open issues, or send PRs my way.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;GitHub Repo&lt;/strong&gt;: &lt;a href="https://github.com/netanelavr/nestjs-metrics-reporter" rel="noopener noreferrer"&gt;nestjs-metrics-reporter&lt;/a&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;strong&gt;NPM Package&lt;/strong&gt;: &lt;a href="https://www.npmjs.com/package/nestjs-metrics-reporter" rel="noopener noreferrer"&gt;nestjs-metrics-reporter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>metrics</category>
      <category>prometheus</category>
      <category>monitoring</category>
    </item>
  </channel>
</rss>
