evolution-gaming / cats-helper

Helpers for cats & cats-effect
MIT License
49 stars 17 forks source link

Generalize ResourceLogOps.log to support arbitrary callbacks #237

Open edubrovski opened 1 year ago

edubrovski commented 1 year ago

It's common to add logs and/or metrics to resource acquisition/release code. There's already a way to log how much time acquisition/release take - ResourceLogOps.log. But to add metrics we have to write code with allocated again. It's error-prone, so I think it makes sense to have this logic in cats-helper. This PR adds a more general observe method that allows to add callbacks for metrics and logs.

The downside is that it's on user to make sure the callbacks can't fail. If a callback after a successful acquire or a callback before the release fail, there will be a resource leak.