Repository: dbader/node-datadog-metrics (js)

Issue:
Export NullReporter for external use
I think it would be super helpful to publicly export the [`NullReporter` class](https://github.com/dbader/node-datadog-metrics/blob/023acfa3a2c5d8dd3f5bbb48c8c02467b2519559/lib/reporters.js#L7-L20) (or just the whole `reporters` module) so consumers can use it. In particular, it’s nice for:
- Tests (plenty of test frameworks have automatic mocking, but setting up an actual `BufferedMetricsLogger` instance with no auto flush and no reporter lets you better inspect exactly what the framework would have sent).
- Disabling metrics in development or temporarily in production (having a version of the logger that doesn’t send is nicer than not creating a logger, because then you don’t have to guard every call-site or make your own mock).

I’d be happy to make a quick PR for this if that’s helpful. (If so, could you let me know what the minimum supported version of Node.js should be (I don’t see it listed anywhere), and therefore whether `exports` in `package.json` or just exporting it from the `index.js` file is preferable?)

Pull request:
Publicly export built-in reporters
This lets people use the built-in `NullReporter` for tests or disabling metrics. I took the route of exposing the entire `reporters` module simplicity and consistency, although it shouldn’t actually be necessary for anyone to ever explicitly use `reporters.DataDogReporter`.

Fixes #67.

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..40d77db
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,29 @@
+on:
+  pull_request: {}
+  push: {}
+
+name: Continuous Integration
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        node_version: [12, 14, 16, 18]
+
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Install Node.js
+        uses: actions/setup-node@v3
+        with:
+          node-version: ${{ matrix.node_version }}
+          cache: 'npm'
+          cache-dependency-path: '**/package.json'
+
+      - name: Install dependencies
+        run: npm install
+
+      - name: Run loader tests
+        run: |
+          npm test
diff --git a/README.md b/README.md
index 1f909f2..9e28caf 100644
--- a/README.md
+++ b/README.md
@@ -122,6 +122,12 @@ Where `options` is an object and can contain the following:
       Datadog-metrics looks for the APP key in `DATADOG_APP_KEY` by default.
 * `defaultTags`: Default tags used for all metric reporting. (optional)
     * Set tags that are common to all metrics.
+* `reporter`: An object that actually sends the buffered metrics. (optional)
+    * There are two built-in reporters you can use:
+        1. `reporters.DataDogReporter` sends metrics to DataDog’s API, and is
+           the default.
+        2. `reporters.NullReporter` throws the metrics away. It’s useful for
+           tests or temporarily disabling your metrics.
 
 Example:
 
@@ -129,6 +135,12 @@ Example:
 metrics.init({ host: 'myhost', prefix: 'myapp.' });
 ```
 
+Disabling metrics using `NullReporter`:
+
+```js
+metrics.init({ host: 'myhost', reporter: metrics.NullReporter() });
+```
+
 
 ### Gauges
 
@@ -181,6 +193,31 @@ Example:
 metrics.histogram('test.service_time', 0.248);
 ```
 
+### Distributions
+
+`metrics.distribution(key, value[, tags[, timestamp]])`
+
+Send a distribution value. Distributions are similar to histograms (they create
+several metrics for count, average, percentiles, etc.), but they are calculated
+server-side on DataDog’s systems. This is much higher-overhead than histograms,
+and the individual calculations made from it have to be configured on the
+DataDog website instead of in the options for this package.
+
+You should use this in environments where you have many instances of your
+application running in parallel, or instances constantly starting and stopping
+with different hostnames or identifiers and tagging each one separately is not
+feasible. AWS Lambda or serverless functions are a great example of this. In
+such environments, you also might want to use a distribution instead of
+`increment` or `gauge` (if you have two instances of your app sending those
+metrics at the same second, and they are not tagged differently or have
+different `host` names, one will overwrite the other — distributions will not).
+
+Example:
+
+```js
+metrics.distribution('test.service_time', 0.248);
+```
+
 ### Flushing
 
 `metrics.flush([onSuccess[, onError]])`
diff --git a/index.js b/index.js
index a0d68a1..8a8893f 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
 'use strict';
 const loggers = require('./lib/loggers');
+const reporters = require('./lib/reporters');
 
 let sharedLogger = null;
 
@@ -45,5 +46,7 @@ module.exports = {
     histogram: callOnSharedLogger.bind(undefined, 'histogram'),
     distribution: callOnSharedLogger.bind(undefined, 'distribution'),
 
-    BufferedMetricsLogger: loggers.BufferedMetricsLogger
+    BufferedMetricsLogger: loggers.BufferedMetricsLogger,
+
+    reporters: reporters
 };


Test patch:
diff --git a/test/module_tests.js b/test/module_tests.js
index 7daf642..f3b00fe 100644
--- a/test/module_tests.js
+++ b/test/module_tests.js
@@ -77,4 +77,9 @@ describe('datadog-metrics', function() {
         metrics.histogram('test.histogram', 23);
         delete process.env.DATADOG_API_KEY;
     });
+
+    it('should publicly export built-in reporters', function() {
+        metrics.reporters.should.have.property('DataDogReporter', reporters.DataDogReporter);
+        metrics.reporters.should.have.property('NullReporter', reporters.NullReporter);
+    })
 });