When implementing a new feature or building a new app, the last thing on my mind is, "how can I tell if something has gone wrong?" I'm biased toward my code. Not that I think it's perfect, I still think about what could go wrong and try to log errors to the best of my ability. But let's be honest: we've all been bitten by something we've written.
Recently, I was working on adding some additional logging to a backend ETL application. This job has become more and more prone to error the longer it has been in use, and it just started get used a lot more recently. I essentially just wanted more details about how much time the app was spending doing certain tasks and which clients were using it the most. There's lots of ways to accomplish this and I was very pleased with the approach I took (a topic I could cover technically in a future post). I went through all the steps on getting these metric logs to output from the app, and lo and behold, my code was not perfect!
This process revealed to me super obvious ways the application could be improved and immediately highlighted the bottlenecks. I went in just wanting to get more valuable information about how the app is used, and came out improving the application performance ten-fold and reducing errors by 100x!
Logging and gathering metrics on your apps performance should not be an afterthought. Your code is not perfect and likely could use quite a bit of optimization. Don't be like me and let your apps use precious resources they don't need. Gather metrics!