node-datadog-metrics icon indicating copy to clipboard operation
node-datadog-metrics copied to clipboard

Export NullReporter for external use

Open Mr0grog opened this issue 2 years ago • 1 comments

I think it would be super helpful to publicly export the NullReporter class (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?)

Mr0grog avatar Sep 14 '22 18:09 Mr0grog

Another approach for my use cases above might be to have a new mock argument to the BufferedMetricsLogger constructor and init that basically equates to no autoflush and a null reporter. hot-shots uses this pattern, for example. But I think just exporting the NullReporter accomplishes things nearly as well with less implementation effort, and gives users more flexibility.

Mr0grog avatar Sep 14 '22 18:09 Mr0grog

This sounds good. Thank you so much for all your hard work to improve the package!! I'm not the original author of this package so I'm not sure what the intended minimum version should be; I'd say best bet would be to adhere to the current approach of exporting from index.js.

ErikBoesen avatar Sep 19 '22 02:09 ErikBoesen