Prevent my crashing gen_server to produce any error message

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Prevent my crashing gen_server to produce any error message

Frank Muller
Hi,

I found this old thread: is there a way to prevent a crashing process from sending a message to error_logger?


but I’m wondering if there is a documented, non-documented or even a hackish way to disable error reports for certain (gen_server) processes (Erlang 20.x or 21.x)?

Thanks for you help/feedbacks
/Frank

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Siri Hansen
With logger (OTP-21.x) you can use process metadata and a filter. For example, in your process' init function, call:
logger:set_process_metadata(#{dont_log=>true}).

Then add a filter which checks for this meta and stops the log - something like:
logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{dont_log:=true}}) -> stop; (_,_) -> ignore end,ok}).

This will turn off all logs issued from the process itself, that is, the termination report from gen_server, the crash report from proc_lib, and any other log issued with the logger API.

It will, however, not turn off the logs issued by the emulator after the process has crashed, i.e. the error report saying "Error in process <...> with exit reason ..." The reason for this is that the emulator has no knowledge of the process metadata, and can not include it in the log event. Therefore, to turn off these messages, you need a filter which can recognize the pid (which is still part of the metadata in this error report). But this is no problem if we're only talking about gen_server processes, since the emulator does not issue error reports for such processes.

Best Regards
/siri





Den tir. 11. sep. 2018 kl. 09:50 skrev Frank Muller <[hidden email]>:
Hi,

I found this old thread: is there a way to prevent a crashing process from sending a message to error_logger?


but I’m wondering if there is a documented, non-documented or even a hackish way to disable error reports for certain (gen_server) processes (Erlang 20.x or 21.x)?

Thanks for you help/feedbacks
/Frank
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Frank Muller
Hi Siri

The filter helped a lot and  less noise are shown on the console. But as you said, not everything is dropped and I can still see a badmatch crash report for example. 

Can you please explain us the PID idea inside the metadata as I’m not familiar with the new logger module?

Thanks
/Frank

Le mar. 11 sept. 2018 à 14:09, Siri Hansen <[hidden email]> a écrit :
With logger (OTP-21.x) you can use process metadata and a filter. For example, in your process' init function, call:
logger:set_process_metadata(#{dont_log=>true}).

Then add a filter which checks for this meta and stops the log - something like:
logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{dont_log:=true}}) -> stop; (_,_) -> ignore end,ok}).

This will turn off all logs issued from the process itself, that is, the termination report from gen_server, the crash report from proc_lib, and any other log issued with the logger API.

It will, however, not turn off the logs issued by the emulator after the process has crashed, i.e. the error report saying "Error in process <...> with exit reason ..." The reason for this is that the emulator has no knowledge of the process metadata, and can not include it in the log event. Therefore, to turn off these messages, you need a filter which can recognize the pid (which is still part of the metadata in this error report). But this is no problem if we're only talking about gen_server processes, since the emulator does not issue error reports for such processes.

Best Regards
/siri





Den tir. 11. sep. 2018 kl. 09:50 skrev Frank Muller <[hidden email]>:
Hi,

I found this old thread: is there a way to prevent a crashing process from sending a message to error_logger?


but I’m wondering if there is a documented, non-documented or even a hackish way to disable error reports for certain (gen_server) processes (Erlang 20.x or 21.x)?

Thanks for you help/feedbacks
/Frank
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Led
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Led
Can you please explain us the PID idea inside the metadata as I’m not familiar with the new logger module?

Thanks
/Frank

Maybe this:

logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{label:={proc_lib,crash}}}) -> stop; (_,_) -> ignore end,ok}).

?

---
Led

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Frank Muller
Still seeing some supervisor crash report:

([hidden email])1> =SUPERVISOR REPORT==== 12-Sep-2018::05:58:53.171292 ===
   supervisor: {local,fah_sup}
   errorContext: child_terminated
   reason: {{badmatch,{<<"945a9769-070b-4635-b0f5-84c2105228f">>,76,45}},
            [{fah,checkid,1,[{file,"src/fah.erl"},{line,210}]},
             [...]    
             {proc_lib,init_p_do_apply,3,
                       [{file,"proc_lib.erl"},{line,249}]}]}
   offender: [{pid,<0.141.0>},
              {id,fah},
              {mfargs,{fah,start_link,[2,#Port<0.9>]}},
              {restart_type,transient},
              {shutdown,5000},
              {child_type,worker}]

I even tried to combine your and Siri’s filter, but no luck.

/Frank

Can you please explain us the PID idea inside the metadata as I’m not familiar with the new logger module?

Thanks
/Frank

Maybe this:

logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{label:={proc_lib,crash}}}) -> stop; (_,_) -> ignore end,ok}).

?

---
Led
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Siri Hansen
There are several different types of reports for a crashing process:

1) for gen* behaviours (gen_server, gen_event, gen_statem, ...), you get an error report issued by the crashing process just before it dies. For a gen_server, these messages start with " ** Generic server <...> terminating". These can be silenced with the process metadata + filter I suggested in my previous mail.

2) for gen* behaviours and other processes started with proc_lib, you get a crash report issued from the crashing process just before it dies. These reports (by default) have the heading == CRASH REPORT==, and the message starts with "crasher: ". These can be silenced with the process metadata + filter I suggested in my previous mail.

3) If the crashed process was part of a supervisor tree, a supervisor report is issued from the process' parent, that is, its supervisor. These reports (by default) have the heading == SUPERVISOR REPORT ==, and the message contains "errorContext: child_terminated". Since they are issued from a different process, these are not silenced by the suggested filter.

4) If the crashed process is not a gen* behaviour, and it is not started by proc_lib, then the emulator issues an error report which starts with "Error in process <...> with exit value:". These are not silenced by the suggested filter.

These are the ones I can think of right now - and I assume that what you see are the supervisor reports only. Is this correct?

How to silence the supervisor report depends on what you want to see from other processes. You can turn off supervisor reports with errorContext child_terminated completely for your system with this filter:

logger:add_primary_filter(stop_sup_reports,{fun(#{log:=#{label:={supervisor,child_terminated}}},_) -> stop; (_,_) -> ignore end, ok}).

or for one specific supervisor (fah_sup) with this one:

logger:add_primary_filter(stop_sup_reports,{fun(#{msg:={report,#{label:={supervisor,child_terminated},report:=R}}},_) -> case proplists:get_value(supervisor,R) of {local,fah_sup} -> stop; _ -> ignore end; (_,_) -> ignore end, ok}).

If the supervisor has other types of children, you might want to silence the reports related to one specific child id (fah) only. Then you can use this filter:

logger:add_primary_filter(stop_sup_reports,{fun(#{msg:={report,#{label:={supervisor,child_terminated},report:=R}}},_) -> Child = proplists:get_value(offender,R), case proplists:get_value(id,Child) of fah -> stop; _ -> ignore end; (_,_) -> ignore end, ok}).

Since I don't know much about what your system does and needs, these are only a few ideas. Another possibility can be to turn off all so called "SASL reports" completely - this would silence reports 2) and 3) for all of your system - if that is acceptable.

The pid-idea from my first mail would only be needed for the emulator logs, 4) in my listing above, which I don't believe you see?



Maybe this:

logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{label:={proc_lib,crash}}}) -> stop; (_,_) -> ignore end,ok}).

?


I assume Len meant to put 'msg' instead of 'meta' here. That would work, but it would silence the crash reports, 2) in my listing above, from all processes, not only the specific ones.

I hope this is of some help!
Kind Regards
/siri



---
Led
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Prevent my crashing gen_server to produce any error message

Frank Muller
You made my day Siri. Working perfectly now and I’m able to suppress all reports from certain type of processes.

The examples you provided should be added to the official doc. 

Thanks again!!!

/Frank

There are several different types of reports for a crashing process:

1) for gen* behaviours (gen_server, gen_event, gen_statem, ...), you get an error report issued by the crashing process just before it dies. For a gen_server, these messages start with " ** Generic server <...> terminating". These can be silenced with the process metadata + filter I suggested in my previous mail.

2) for gen* behaviours and other processes started with proc_lib, you get a crash report issued from the crashing process just before it dies. These reports (by default) have the heading == CRASH REPORT==, and the message starts with "crasher: ". These can be silenced with the process metadata + filter I suggested in my previous mail.

3) If the crashed process was part of a supervisor tree, a supervisor report is issued from the process' parent, that is, its supervisor. These reports (by default) have the heading == SUPERVISOR REPORT ==, and the message contains "errorContext: child_terminated". Since they are issued from a different process, these are not silenced by the suggested filter.

4) If the crashed process is not a gen* behaviour, and it is not started by proc_lib, then the emulator issues an error report which starts with "Error in process <...> with exit value:". These are not silenced by the suggested filter.

These are the ones I can think of right now - and I assume that what you see are the supervisor reports only. Is this correct?

How to silence the supervisor report depends on what you want to see from other processes. You can turn off supervisor reports with errorContext child_terminated completely for your system with this filter:

logger:add_primary_filter(stop_sup_reports,{fun(#{log:=#{label:={supervisor,child_terminated}}},_) -> stop; (_,_) -> ignore end, ok}).

or for one specific supervisor (fah_sup) with this one:

logger:add_primary_filter(stop_sup_reports,{fun(#{msg:={report,#{label:={supervisor,child_terminated},report:=R}}},_) -> case proplists:get_value(supervisor,R) of {local,fah_sup} -> stop; _ -> ignore end; (_,_) -> ignore end, ok}).

If the supervisor has other types of children, you might want to silence the reports related to one specific child id (fah) only. Then you can use this filter:

logger:add_primary_filter(stop_sup_reports,{fun(#{msg:={report,#{label:={supervisor,child_terminated},report:=R}}},_) -> Child = proplists:get_value(offender,R), case proplists:get_value(id,Child) of fah -> stop; _ -> ignore end; (_,_) -> ignore end, ok}).

Since I don't know much about what your system does and needs, these are only a few ideas. Another possibility can be to turn off all so called "SASL reports" completely - this would silence reports 2) and 3) for all of your system - if that is acceptable.

The pid-idea from my first mail would only be needed for the emulator logs, 4) in my listing above, which I don't believe you see?



Maybe this:

logger:add_primary_filter(my_filter_id,{fun(#{meta:=#{label:={proc_lib,crash}}}) -> stop; (_,_) -> ignore end,ok}).

?


I assume Len meant to put 'msg' instead of 'meta' here. That would work, but it would silence the crash reports, 2) in my listing above, from all processes, not only the specific ones.

I hope this is of some help!
Kind Regards
/siri



---
Led
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions