Live data from Hacker News

Log by time, not by count

johnscolaro.xyz

1–10 of 109 posts

Re: Log by time, not by count

#2
This post falls into a common trap; conflating logging with metrics.

Log interesting things, where interesting is defined as context outside what the "happy path" execution performs.

Collect and make available system metrics, such as invocation counts, processing time histograms, etc., to make available what the post uses log statements to disseminate same.

Re: Log by time, not by count

#3
I agree with this. Logging, as well as metrics and tracing, are such hard topics for me to wrap my head around though.

From the log consumer (person) perspective, you'd want logs to provide you with sufficient information when troubleshooting. But since trouble usually happens when things go wrong in unexpected ways, the logging likely won't be well aligned to emit the right info for you to figure out what's going wrong exactly. What then, are you supposed to log the entire application state and every change to it? But then that's way too expensive, and there's a decent chance you might just drown in the noise instead. So you're left with this half artform half science type deal.

One thing I'm grateful for is that over the years most everything now logs in JSON lines at least. I just wish there was a standardized, simple way to access all the possible kinds of JSON objects that might be emitted into the logs. A schema would be a good start, but then I can immediately see ways how that would be quickly rendered lot less useful early on (e.g. "this and that field can contain some other serialized JSON object, good luck!").

Re: Log by time, not by count

#5
Aggregation by time and count together is a normal batching technique and I have used it a lot to scale out multiple parts of many systems.

In this particular example, I agree with others: this is a case for metrics. "Log errors, metric successes[0]."

0: success events (a bit more than a log typically) may be important, especially if tied to something you charge for.

Re: Log by time, not by count

#6

I agree with this. Logging, as well as metrics and tracing, are such hard topics for me to wrap my head around though. From the log consumer (person) perspective, you'd want logs to provide you with sufficient information when troubleshooting. But since trouble usually happens when things go wrong in unexpected ways, the logging likely won't be well aligned to emit the right info for you to figure out what's going wr…

> What then, are you supposed to log the entire application state and every change to it?

For replayability/state reconstruction, usually it's enough to log the input data and the decisions made upon them i.e. which branches of the if/switch (and things morally equivalent to them e.g. virtual functions and short-circuiting Boolean operators) you've actually taken.

> But then that's way too expensive,

Yes, it's usually still way too expensive. But when it's not, it does give you information about at what code point exactly the "wrong" decision was made, and from there you can at least start thinking about how the system could get into the state where it would start making "wrong" decisions at this precise point of code — and that usually cuts down the number of possible reasons tremendously.

Re: Log by time, not by count

#7

I agree with this. Logging, as well as metrics and tracing, are such hard topics for me to wrap my head around though. From the log consumer (person) perspective, you'd want logs to provide you with sufficient information when troubleshooting. But since trouble usually happens when things go wrong in unexpected ways, the logging likely won't be well aligned to emit the right info for you to figure out what's going wr…

My personal answer to this is logging very little during normal operation and then logging a lot during errors. Depending on the maturity of the system “a lot” might mean the entire state so I can debug afterwords.

Re: Log by time, not by count

#8

I agree with this. Logging, as well as metrics and tracing, are such hard topics for me to wrap my head around though. From the log consumer (person) perspective, you'd want logs to provide you with sufficient information when troubleshooting. But since trouble usually happens when things go wrong in unexpected ways, the logging likely won't be well aligned to emit the right info for you to figure out what's going wr…

Everything is events. The problem is that, as you notice, you frequently encounter situations where there are too many events to handle. Metrics, logging, and tracing are just three different ways to handle that problem.

Metrics handles too many events by aggregating them. You handle too many events by squashing them into a smaller number of events that aggregate the information.

Logging handles too many events by sampling them. If you have N times as many events as you can handle, take 1 in N of them or whatever other sampling model you want.

Tracing is logging, but where you have chains of correlated events. If you have a request started and a request ended event, it is pretty useless to get one without the other. So, you sample at the "chain of correlated events" level. You want 1 in N "chains of correlated events".

But, if you have enough throughput for all your events, just get yourself a big pile of events and throw it into a visualizer. Or better yet, just enable time travel debugging tracing so you do not need to even need to figure out how the events map to your program state.

Re: Log by time, not by count

#9

I agree with this. Logging, as well as metrics and tracing, are such hard topics for me to wrap my head around though. From the log consumer (person) perspective, you'd want logs to provide you with sufficient information when troubleshooting. But since trouble usually happens when things go wrong in unexpected ways, the logging likely won't be well aligned to emit the right info for you to figure out what's going wr…

> I just wish there was a standardized, simple way to access all the possible kinds of JSON objects that might be emitted into the logs. A schema would be a good start ...

While not an industry standard, an open source specification for JSON log entries commonly used is ECS[0]. There are others, but this one can serve a system well IMHO.

0 - https://www.elastic.co/docs/reference/ecs/ecs-guidelines

Re: Log by time, not by count

#10

This post falls into a common trap; conflating logging with metrics. Log interesting things, where interesting is defined as context outside what the "happy path" execution performs. Collect and make available system metrics, such as invocation counts, processing time histograms, etc., to make available what the post uses log statements to disseminate same.

Thanks for taking the time to reply! I'm relatively new to working on this type of system (large scale, event driven) and half posted because I know there are people on HN way better than me at this, and was curious about their opinions.

In the end, what's the difference between a log and a metric? Is one structured, and one unstructured? Is one a giant blob of text, and the other stored in a time series db? At the moment I guess I'm "logging my metrics" with structured logs going into Loki which can then unwrap and plot things.

You and the other commenters have given me the vocabulary to dig more into this area on the internet though. Thanks!

Post reply on HN