Description
Use case
Metrics doesn't (currently) have a good way to silence all output during unit tests (it requires configuration changes outside the scope of the unit test code.) To work around this I was going to use a fake implementation of the MetricsInterface
interface, and pass that to actual code that generates metrics, instead of passing a reference to the concrete Metrics
class. At unit test time I can instead pass a fake implementation of this interface that just silently swallows all requests. The problem with this workaround is that the MetricsInterface.singleMetric()
method has to return a concrete implementation of Metrics
.
Solution/User Experience
Change MetricsInterface.singleMetric()
to return MetricsInterface
. I don't think (?) this should break anything, and will allow me to replace the concrete implementation at unit test time.
Alternative solutions
Add functionality to the MetricsOptions interface (used in the Metrics class constructor) to take an option something like "silent" which tells the implementation not to log. Or allow passing a custom output sink. I think these are both better options long term, but my suggestion I think is a one-liner that probably fits better with the design anyway (it's typically best to not have interfaces have types that return concretions).
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status