Theo Gravity

LogLayer v7 - Seamlessly add metrics to your logging code

by
Auto-instrumentation gives baseline metrics, but you need pinpointed metrics for custom logic. Metrics often get forgotten because they require separate code paths from logs. LogLayer v7 adds StatsD support via hot-shots, letting you send metrics and logs in one call. When you log an error, increment your counter. When you log a request, track its duration. Metrics and logs stay in sync.

Add a comment

Replies

Best
Theo Gravity
I'm the author of LogLayer, a TypeScript abstraction layer for logging libraries with the ability to send logs to cloud providers like DataDog. It's made for outputting structured logs, and I've designed the logging APIs to reflect that: log.withMetadata({ userId: 123 }) .withError(new Error()) .error("Something's wrong!") Depending on the logging library you're using with LogLayer, it might look like: { "msg": "Something's wrong!", "metadata": { "userId": 123 }, "err":{ "type": "Error", "message": "test", } } The idea is if you decide the logging library isn't fulfilling your needs, you can easily swap out the library where LogLayer is initialized without having to change the code you've already written around logs. This weekend, I launched v7 of LogLayer, which adds support for mixins. I wanted to keep LogLayer's API focused solely on logging, but also have the ability to extend it if needed. The use-case that came up is my workplace wants better metrics. We do have auto-instrumentation for our systems, but there are times where we want more pin-pointed metrics. I've noticed in some cases, metrics and logging goes hand-in-hand, and thought that it'd be really nice if I could access the same logging client and be able to send metrics to StatsD as I write my logs. In node.js land, I believe "hot-shots" is *the* StatsD client most would use, and created a mixin with it, which adds the hot-shots methods to the LogLayer API. So now you have the ability to send metrics + logs at the same time if you wanted this functionality: log.statsIncrement("error.count") .withMetadata({ userId: 123 }) .withError(new Error()) .error("Something's wrong!") This will now send an increment call to StatsD in addition to shipping out your log to your logging library / cloud provider. I'm hoping with this DX, thinking about metrics won't be an afterthought because you now have easy access to send it while writing logs. (You can also send metrics without sending logs with the mixin.)
Chilarai M

Combining logs and metrics in one flow is such a practical win for observability. StatsD integration via hot-shots makes it super convenient to keep everything consistent without extra setup. Great work!