halostatue
Cost of stack traces for logging?
We were having a discussion at work about logging:
I was thinking about the pros and cons of adding stack traces to log metadata last week, and the difference between the messages we log for helping operate the system and the messages which get presented to the real end user (see kevlinhenney on twitter for endless examples of diagnostics ending up in user interfaces).I was wondering about having a function to automatically bundle stacktrace information into a log message so we could do something like:
# stripped down code to handle a failure # e.g. {:error, posix} = File.open(filename) message = "Failed to open #{filename}" #{:file.format_error(posix)} OurLogger.error(message) {:error, message}And
OurLoggercould massage and addstacktrace: Process.info(self(), :current_stacktrace)to the metadata. The log formatter could then display stack traces for error and higher?Then the application sending a result to the eventual human would have to make sure it presented an appropriate message for the user.
This sounds…possible, but it feels like it would be very expensive to achieve. Obviously, we’d never implement this without benchmarking getting a stacktrace, but what I wonder is whether cost is that high?
If it’s low, would there be a reason to add this to Elixir’s logger by default?
Most Liked
hauleth
If you log anything above error and you do not crash at least process, then I think that you use logging system incorrectly.
To extend a little on levels error and above:
error- application errors, recoverable, but in higher volumes may require further introspectioncritical- system has met unrecoverable error that still do not bring the whole application down, may require more immediate action from the operatoralert- do something with that error right here, right nowemergency(also known aspanic) - all hands on deck, we have been thrown of course just a tad, asteroids are smashing at the hull, we are going into the Sun, and we are also out of coffee
halostatue
@NobbZ The example given was illustrative only. There are plenty of cases where something is an error, but potentially recoverable—especially when dealing with external systems (this is mostly what our services do).
In general, I agree with @hauleth’s levels, although to me alert is more right here, right now.
Thanks for the thoughts on this; it confirms the feeling that I had on the cost of stacktrace acquisition.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








