Support multiple reporter instances
Mr0grog opened this issue · 0 comments
While working on #80, I noticed that you can’t instantiate multiple instances of DataDogReporter
(or, you can, but they will behave the same, and creating a reporter will alter any that you have already made). This is mainly because the underlying metricsApi
object is scoped to the whole module, rather than to each instance of DataDogReporter
.
This prevents someone from having two loggers with different credentials (probably not a common case, but it ought to work), and will be a bigger problem if we ever lean on configuration built-into the @datadog/datadog-api-client
package for more than just credentials and what site you are submitting to.
I assume the reason for this was to keep access private. There are a couple instance-specific ways to do this:
- Use
WeakMap
. Adds a little more boilerplate, but is supported in all version of Node.js we are compatible with. - Use private class fields. These are much nicer, syntax-wise, but I believe requires bumping the minimum version of Node.js to 14 (and switching to the newer
class
syntax, which we should probably do anyway).