-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Structured logging mod bosh and mod bosh socket #2823
Structured logging mod bosh and mod bosh socket #2823
Conversation
Codecov Report
@@ Coverage Diff @@
## structured_logging #2823 +/- ##
======================================================
+ Coverage 73.34% 78.69% +5.34%
======================================================
Files 373 373
Lines 30929 30954 +25
======================================================
+ Hits 22686 24358 +1672
+ Misses 8243 6596 -1647
Continue to review full report at Codecov.
|
src/mod_bosh.erl
Outdated
[Reason]), | ||
?LOG_ERROR(#{ | ||
issue => bosh_stop, | ||
issue=>undefined_condition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will override the previous value :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch
src/mod_bosh.erl
Outdated
@@ -174,7 +174,7 @@ init(Req, _Opts) -> | |||
info(accept_options, Req, State) -> | |||
Origin = cowboy_req:header(<<"origin">>, Req), | |||
Headers = ac_all(Origin), | |||
?DEBUG("OPTIONS response: ~p~n", [Headers]), | |||
?LOG_DEBUG(#{options_response => Headers}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, what field is required.
?LOG_DEBUG(#{what => bosh_accept_options, text => <<"Handle OPTIONS request in Bosh">>, headers => Headers})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it in all other log maps too.
src/mod_bosh.erl
Outdated
@@ -161,7 +161,7 @@ node_cleanup(Acc, Node) -> | |||
-type option() :: {atom(), any()}. | |||
-spec init(req(), _Opts :: [option()]) -> {cowboy_loop, req(), rstate()}. | |||
init(Req, _Opts) -> | |||
?DEBUG("issue=bosh_init", []), | |||
?LOG_DEBUG(#{issue => bosh_init}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should log req
field in this module where is possible. So we can format it later in logs.
src/mod_bosh.erl
Outdated
%% Remember req_sid, so it can be used to print a debug message in bosh_reply | ||
forward_body(Req1, BodyElem, S#rstate{req_sid = Sid}); | ||
info({bosh_reply, El}, Req, S) -> | ||
BEl = exml:to_binary(El), | ||
?DEBUG("issue=bosh_send sid=~ts req_sid=~ts reply_body=~p", | ||
[exml_query:attr(El, <<"sid">>, <<"missing">>), S#rstate.req_sid, BEl]), | ||
?LOG_DEBUG(#{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?LOG_DEBUG(#{what => bosh_send, sid => exml_query:attr(El, <<"sid">>, <<"missing">>),
req_sid => S#rstate.req_sid, reply_body => BEl}),
{reply, ok, accumulate, State}. | ||
|
||
normal(Event, _From, State) -> | ||
?DEBUG("Unhandled sync event in 'normal' state: ~w~n", [Event]), | ||
?LOG_DEBUG(#{what => bosh_socket_unhandled_sync_event, state => normal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state_name
instead of state
.
And indention for record should be different (second line should start below what).
@@ -341,7 +348,8 @@ handle_sync_event(get_cached_responses, _From, StateName, | |||
#state{sent = CachedResponses} = S) -> | |||
{reply, CachedResponses, StateName, S}; | |||
handle_sync_event(Event, _From, StateName, State) -> | |||
?DEBUG("Unhandled sync all state event: ~w~n", [Event]), | |||
?LOG_DEBUG(#{what => bosh_socket_unhandled_sync_all_state, state => State, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG_DEBUG(#{what => bosh_socket_unhandled_event,
@@ -373,11 +381,12 @@ handle_info(close, _SName, #state{pending = []} = State) -> | |||
handle_info(close, _SName, State) -> | |||
{next_state, closing, State}; | |||
handle_info(inactivity_timeout, _SName, State) -> | |||
?INFO_MSG("terminating due to client inactivity~n", []), | |||
?LOG_INFO(#{what => bosh_socket_terminating, reason => "client inactivity"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text => <<"Terminating due to client inactivity">>
{stop, {shutdown, inactivity_timeout}, State}; | ||
handle_info({wait_timeout, {Rid, Pid}}, SName, | ||
#state{handlers = Handlers} = S) -> | ||
?INFO_MSG("'wait' limit reached for ~p~n", [Pid]), | ||
?LOG_INFO(#{what => bosh_socket_wait, reason => "process reached limit", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what => bosh_socket_wait_timeout
. bosh_pid
and rid
fields.
@@ -389,15 +398,16 @@ handle_info({wait_timeout, {Rid, Pid}}, SName, | |||
{next_state, SName, NS} | |||
end; | |||
handle_info(Info, SName, State) -> | |||
?DEBUG("Unhandled info in '~s' state: ~w~n", [SName, Info]), | |||
?LOG_DEBUG(#{what => bosh_socket_unhandled_info, s_name => SName, | |||
state => Info}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg => Info
.
And we usually name that case as what => unexpected_message
{next_state, SName, State}. | ||
|
||
terminate(_Reason, StateName, #state{sid = Sid, handlers = Handlers} = S) -> | ||
[Pid ! {close, Sid} || {_, _, Pid} <- lists:sort(Handlers)], | ||
mod_bosh_backend:delete_session(Sid), | ||
catch ejabberd_c2s:stop(S#state.c2s_pid), | ||
?DEBUG("Closing session ~p in '~s' state. Handlers: ~p Pending: ~p~n", | ||
[Sid, StateName, Handlers, S#state.pending]). | ||
?LOG_DEBUG(#{what => bosh_socket_closing_session, session_id => Sid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sid
field name for consistency. And state_name
?INFO_MSG("request ~p repeated but no response found in cache ~p~n", | ||
[Rid, Sent]), | ||
?LOG_INFO(#{what => bosh_socket_request_repeated, rid => Rid, | ||
issue => "request repeated but no response found in cache", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text => <<"Bosh request repeated but no response found in cache">>
@@ -847,7 +857,8 @@ get_client_acks(streamstart, Element, Default) -> | |||
<<"1">> -> | |||
true; | |||
_ -> | |||
?INFO_MSG("ignoring invalid client ack on stream start~n", []), | |||
?LOG_INFO(#{what => bosh_socket_ignore_ack, | |||
details => "ignoring invalid client ack on stream start"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text
field instead of details. Text should be a binary.
?LOG_DEBUG(#{ | ||
what => bosh_socket_cannot_send_stream_end, | ||
issue => "can't send stream end", | ||
reason => "pending stanzas"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include stanzas
merged |
This PR adds structered logging to
mod_bosh
andmod_bosh_socket
.It is created no to be merged to #2816 but not to mess up work for other devs.