stefanchrobot

stefanchrobot

Error logging in Elixir with OTP 21+

I’m trying to prevent leaking of application secrets and personally identifiable information (PIIs) into logs. One thing is obviously making sure that we don’t log that kind of data explicitly. But the other part is taming the built-in error reporters.

When my application was first deployed to the servers, there was a misconfiguration and it crashed badly. While that happened, the error reporter logged the state of a supervisor process and the last received message. The state contained API keys. If I write a simple GenServer that crashes, it’s pretty easy to reproduce the log entry with the last message. For some reason, I’m unable to make the error reporter log the process state.

I have a few questions around this:

  1. When is the state of the process logged?
  2. Is it possible to prevent logging of the last message and the state of the process?
  3. Is it possible to prevent logging of general errors (match error might leak sensitive data too)?

I’m also a bit confused about the documentation. Since I’m on OTP 21+, the docs state that:

SASL Reports
By SASL reports we mean supervisor reports, crash reports and progress reports.
Prior to Erlang/OTP 21.0, these reports were only logged when the SASL application was running, and they were printed trough SASL’s own event handlers sasl_report_tty_h and sasl_report_file_h. (…) Due to the specific event handlers, the output format slightly differed from other log events.
As of Erlang/OTP 21.0, the concept of SASL reports is removed, meaning that the default behaviour is as follows:

  • Supervisor reports, crash reports, and progress reports are no longer connected to the SASL application.
  • Supervisor reports and crash reports are issued as error level log events, and are logged through the default handler started by Kernel. (…)
  • The output format is the same for all log events.

On the other hand, the Elixir’s Logger docs state that I should set the :handle_otp_reports and :handle_sasl_reports options to true and start the :sasl application before the :logger to handle the process crash reports as usual Elixir logs.

  1. Is this still true when running on OTP 21+?

Most Liked

blatyo

blatyo

Conduit Core Team

I don’t have the direct answers you’re looking for. However, I wanted to point out custom struct inspections, which is a relatively new feature. It allows you to specify which fields show when a struct is inspected. This applies to logs, because when state is printed to logs, it is inspected first.

stefanchrobot

stefanchrobot

Thanks! At first I thought that it’s really not the answer I’m looking for. Well, after some thought, it turns out that it actually is! It’s enough to wrap sensitive data in a struct and implement Inspect for it.

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement