One of the benefits of swift-metrics being an API-only package is that it doesn't contain anything you don't need. The drawback being that it may not contain some of the things you do want!
As such I'd like to pitch a small package containing a set of tools related to swift-metrics
.
Proposed tools:
- Logging factory: a
MetricsFactory
which logs any changes to the underlying instruments. Logging would be limited toswift-log
orprint
. This is helpful for general debugging and sanity-checking during development. - Delegating factory:
MetricsFactory
which delegates to a "current" factory. Since it is only possible to bootstrap the metrics system once per process (testable imports aside) it makes testing more difficult as noted in Re-initializing swift-metrics in tests · Issue #60 · apple/swift-metrics · GitHub. The factory would be a singleton which would delegate to a swappable, user-provided factory. It would also have to keep track of where each instrument originates in order to correctlydestroy
them. This would allow the factory to be swapped out depending on test requirements. It could also handle the awkwardness of installing itself since the user would otherwise have to do keep track of this in tests. - Capture factory: a
MetricsFactory
which records structured events in a way that is suitable for testing. The rough idea being "I executed this code path and I want to check that this counter was incremented by this value and has this label and these dimensions". This requires some more exploration as to what shape this would take to be maximally useful here.
I'm curious as to whether the community thinks there's enough value in having a such a package, whether the proposed tools would be useful, and if there are any other suggestions for factories or otherwise which could be included here.