News for hackers. Stuff that matters.
Re:Do Not Log by fuzzy2 on Wednesday January 05, 2022 @11:05AM (#29810663)
How is using Sentry (or whatever) not adding complexity? How is Sentry not introducing side effects? How is using Sentry magically creating information about why a business operation failed? Does Sentry even know your business operation failed? It doesn’t, unless you tell it. How is Sentry not I/O-bound? (That’s right, they abstracted that away, like a good logging framework does, too.)

In the end, to integrate Sentry and get actually useful information for monitoring, you have to do the same work you’d do for logging. Except now you’re tied to Sentry. Want some other service? Good luck.

Do log. And then send the log messages to Sentry or whatever you’re using, too.

Also, do overlog. It can be hard or impossible to attach a debugger to the deployed application. But you can always turn the log level up to 11 and then reconstruct what happened from the log messages.

Re:Do Not Log by kemitche on Wednesday January 05, 2022 @11:26AM (#29811005)
Also... Sentry is logging. It's a very fancy logger that can capture all sorts of data about the exception and what was happening - but at its core, it's still a essentially a logger.
Re:Do Not Log by wldcordeiro on Wednesday January 05, 2022 @11:37AM (#29811190)
I was thinking the same thing once they got to that point! Our "logger" is literally a library from DataDog, but Sentry has similar (we actually migrate from Sentry to DataDog at my job) and there's tons of other services now that do similar with "loggers" as well. There is good advice here about questioning when to log but Sentry and its peers are loggers.
Re:Do Not Log by fourseventy on Wednesday January 05, 2022 @11:49AM (#29811380)
Ya exactly. I came here to say this too.
Re:Do Not Log by konschubert on Wednesday January 05, 2022 @11:07AM (#29810707)
I think what the post is trying to say is that you should let your exception bubble up.

And then catch it at the highest level, including all the stack trace. And then maybe send it to sentry, or log it, put it on data dog.

But don't catch exceptions all over your application code.

I have a related mental model for this: When you crash, crash loudly.

Re:Do Not Log by masklinn on Wednesday January 05, 2022 @11:12AM (#29810781)
That, however, does not at all work when exceptions are part of the "normal" process and should be ignored or cleanly retried (having spent a while interacting with github, if you take the entire thing down every time github replies with an error and log that to sentry, your sentry instance will last all of 5mn before you have to declare bankruptcy or just plonk the alters and ignore everything).

But in that case you probably still want to know about these failures, so you can review them from time to time, or see if there are upticks in failure frequency.

Re:Do Not Log by chousuke on Wednesday January 05, 2022 @11:32AM (#29811096)
I think errors and failures get often conflated. There are truly exceptional situations where your application can do nothing and will just have to abort (passing off the failure to a higher layer in the system) but often failures aren't really exceptional. You can not assume that your database connections live forever, for example, and it's not an error when a commit fails due to an interrupted network connection. Such cases need to be handled.

If you know that an operation is unreliable, you need to add retry / recovery logic and perhaps log or increment a metric that you can track what's going on; a high number of failures often indicates an exceptional situation.

In some cases, your retry logic will be a "Please try again" message to the user. I think that's perfectly acceptable, but you'll still want to know about it.

Re:Do Not Log by Veuxdo on Wednesday January 05, 2022 @11:16AM (#29810856)
Exceptions should not be normal by definition.
Re:Do Not Log by mkohlmyr on Wednesday January 05, 2022 @11:32AM (#29811099)
That's a wonderful theory.

I have a third party which returns errors ~20% of the time outside of working hours (yes, really).

1. Exceptions should be sent to sentry. 2. Exceptions should not be normal. 3. Do not log.

Solve for ability to review & debug after the fact.

Re:Do Not Log by frenchyatwork on Wednesday January 05, 2022 @11:57AM (#29811497)
> I have a third party which returns errors ~20% of the time outside of working hours

Then presumably those errors shouldn't be exceptions. Of course, there's a lot of a lot of assumptions behind this:

1. You have control over the code that interfaces with the third party. Otherwise presumably you'd have to write a shim that catches the exception and turns it into an error value, and that's probably not worth the effort.

2. You're work in a language that doesn't type check exceptions (i.e. not Java with checked exceptions) and your language also doesn't have a nicer way of handling errors as a (discriminated) union.

3. Your co-workers will go complete bananas if you start using some sort of result type or [success, value|error] tuple instead of an exception because that's how they've done it for 20 years.

The reason for this is that exceptions in most languages escape the type system and are in general more awkward to catch.

Of course, I'd also disagree with "do not log" in this context, though I might prefer a logging mechanism that allowed me to write queries on it (like recording values in a database).

Re:Do Not Log by marcosdumay on Wednesday January 05, 2022 @12:56PM (#29812442)
Well, unless it's reasonable for your own software to fail the same 20% of the time (well, more, but knowing how much more requires more information) when outside of working hours, you will always need a shim anyway.
Re:Do Not Log by Veuxdo on Wednesday January 05, 2022 @11:40AM (#29811240)
If it doesn't work that often, then it isn't an expectation. That's just how it works.
Re:Do Not Log by chousuke on Wednesday January 05, 2022 @11:34AM (#29811135)
In some languages, the standard way to signal failure is to throw an exception. You can't really define exceptions as abnormal in those cases, because failures are part of normal operation; you can't expect them not to happen if you want robust software.
Re:Do Not Log by Veuxdo on Wednesday January 05, 2022 @11:44AM (#29811295)
Why not return an error in the case of an anticipated failure? You don't have to use exceptions for that.
Re:Do Not Log by formerly_proven on Wednesday January 05, 2022 @12:01PM (#29811560)
Because that's highly un-idiomatic in pretty much every language that has exceptions, except G++, which arguably doesn't really have exceptions as they are strengstens verboten.

Even if you really really like error return codes and really really don't like exceptions, you'll likely agree that writing very un-idiomatic code that goes against the grain of the language and all the libraries you might be using is likely a much bigger loss than the value you might have added by avoiding exceptions in your part of the block.

Re:Do Not Log by Veuxdo on Wednesday January 05, 2022 @12:08PM (#29811671)
It's really comes down to wether you think exceptions are an everyday thing not. I like going by the dictionary definition of the word "exception" which states that they are not.

Out of curiosity, in what languages are error return types non-idiomatic?

Re:Do Not Log by slaymaker1907 on Wednesday January 05, 2022 @12:29PM (#29811973)
Python and Java are two that come to mind. It is idiomatic in both to return null/None on error, but it is not idiomatic to use a result type. Hell, Python even uses exceptions to terminate iterators.

This isn't to say the idioms are never broken or that they shouldn't be broken. I agree that if you are doing something like parsing a string to an integer, that should probably be a result type and not just throw an exception.

Re:Do Not Log by chousuke on Wednesday January 05, 2022 @12:35PM (#29812080)
In almost all dynamic languages I know of for example. Way too easy to forget about error handling if you use values. Exceptions at least tend to cause noise.

In languages like Java an Python, you can return error values but because you can also always return nulls, you're just making more trouble for yourself than it's worth avoiding exceptions.

Re:Do Not Log by ivas on Wednesday January 05, 2022 @12:41PM (#29812168)
In your code, you don't have to use exceptions to indicate a failure but you still have to catch exceptions thrown by third-party libraries (or their dependencies).

It is not easy to stay away from exceptions if your language supports them.

Re:Do Not Log by contravariant on Wednesday January 05, 2022 @11:27AM (#29811019)
With some systems I have indeed been tempted a few times to only throw an exception if everything went right in one try, but my suggestions have been rejected so far.
Re:Do Not Log by cortesoft on Wednesday January 05, 2022 @01:43PM (#29813131)
How frequently does it have to occur to be normal? 50% of the time? 5%? .005%?
Re:Do Not Log by jjnoakes on Wednesday January 05, 2022 @12:47PM (#29812284)
Depends on the language and library.

But even for exceptional exceptions, you may still want or need to retry or branch based on what was thrown.

Re:Do Not Log by konschubert on Wednesday January 05, 2022 @11:27AM (#29811023)
That, or a count metric.
Re:Do Not Log by KallDrexx on Wednesday January 05, 2022 @12:48PM (#29812307)
> I think what the post is trying to say is that you should let your exception bubble up.

It's not an either-or situation though. Even if you let the exception bubble up and sentry logs the exception, logging performed prior to the exception and at the time the exception is caught (prior to being bubbled up) as valuable context to how the exception happens, which can lower debugging time.

The exception just tells you that something went done, it doesn't always have the reason why something went wrong. And the context for why is not always available at the time of raising the exception (the context may be from a prior function call, or the consumer of the function that raised the exception).

Re:Do Not Log by vanusa on Wednesday January 05, 2022 @11:37AM (#29811183)
I think what the post is trying to say is that you should let your exception bubble up.

Usually, but not always. That is, for the classic "exceptions should only be used in exceptional cases" scenario, this is usually what you want to do.

A good portion of the time, though, this scenario doesn't apply. You're dealing with a subsystem that is throwing an exception (for good reasons or bad) but no, you don't want to just the application crash. You want to ... catch it, and do something else.

Which is what try-catch was devised for in the first place, after all.

Re:Do Not Log by ninkendo on Wednesday January 05, 2022 @01:20PM (#29812828)
Eh... a lot of this article can be reworded as "do error handling better" (make error paths unreachable through your type system, crash for unrecoverable errors, if errors are recoverable, they should be Results, etc etc.)

Ok, I did all that. And I still want to know why this bug report happened, and logs help me. Why should I Not Log?

Re:Do Not Log by fuzzy2 on Wednesday January 05, 2022 @11:13AM (#29810802)
Not really a point I read in TFA but I agree. Catching just to log something is generally wrong.
Re:Do Not Log by simion314 on Wednesday January 05, 2022 @11:23AM (#29810951)
> Catching just to log something is generally wrong

Yes, but you should catch as soon as possible (or validate stuff as soon ass possible) and re-throw with a better error message if possible. You will thank yourself when some problem appears and instead of a random "errorcode 123" you get a detailed message like "Operation Xyz failed with errorcode 123";

Re:Do Not Log by jaredsohn on Wednesday January 05, 2022 @11:43AM (#29811282)
>Except now you’re tied to Sentry. Want some other service? Good luck.

If this is a concern, just create a class with a method that takes an exception, message, context, etc. as parameters and use that. Now you can change it in one place instead of throughout your codebase.

Agree on logging messages as well; is useful to see live what is happening in the system as well as it is useful to see logging broken up by different errors

Re:Do Not Log by outworlder on Wednesday January 05, 2022 @12:52PM (#29812377)
> Also, do overlog. It can be hard or impossible to attach a debugger to the deployed application. But you can always turn the log level up to 11 and then reconstruct what happened from the log messages.

Please don't overlog. Only ever do this if you can dynamically change your log level on demand, without impacting users.

If you do have to reconstruct a sequence of events and you do not have distributed tracing, fine. Log the sequence of events _when needed_.

But please don't log messages on a perfectly fine system for no reason. It's noise and health can be better served by looking at metrics.

Because of this overlogging nonsense our systems generate terabytes of logs daily. Most of it is never ever looked at.

Re:Do Not Log by fuzzy2 on Wednesday January 05, 2022 @01:32PM (#29812987)
Well yes of course? That’s what log levels and log categories are for. Whether the configuration can change at runtime or if your services have to cycle doesn’t really matter IMHO.