@@ -54,7 +54,7 @@ init({N, #{name := Name} = Config}) ->
5454-spec handle_cast ({event , bugsnag_api_error_reporting :event ()}, state ()) ->
5555 {noreply , state ()}.
5656handle_cast ({event , Event }, # bugsnag_state {} = State ) when is_map (Event ) ->
57- send_pending (Event , State );
57+ maybe_send_next (Event , State );
5858handle_cast (_ , State ) ->
5959 {noreply , State }.
6060
@@ -68,24 +68,27 @@ handle_info({http, {Ref, {{_, 200, _}, _, _}}}, #bugsnag_state{pending = Ref} =
6868handle_info (
6969 {http , {Ref , {{_ , Status , ReasonPhrase }, _ , _ }}}, # bugsnag_state {pending = Ref } = State
7070) ->
71- ? LOG_WARNING (#{what => send_status_failed , status => Status , reason => ReasonPhrase }),
71+ ? LOG_WARNING (#{what => send_status_failed , http_status => Status , http_reason => ReasonPhrase }),
7272 send_pending (State # bugsnag_state {pending = undefined });
7373handle_info ({http , {Ref , Unknown }}, # bugsnag_state {pending = Ref } = State ) ->
74- ? LOG_WARNING (#{what => send_status_failed , reason => Unknown }),
74+ ? LOG_WARNING (#{what => send_status_failed , http_reason => Unknown }),
7575 send_pending (State # bugsnag_state {pending = undefined });
7676handle_info (_Info , State ) ->
7777 {noreply , State }.
7878
7979% Internal API
8080
81- send_pending (
81+ maybe_send_next (
8282 Event ,
8383 # bugsnag_state {acc = Acc , acc_size = Limit , acc_limit = Limit , base_event = BaseEvent } = State
8484) ->
8585 {{value , ToDiscard }, Acc1 } = queue :out (Acc ),
8686 ? LOG_WARNING (#{what => bugsnag_discarding_event_overflow , event => ToDiscard }),
87- send_pending (State # bugsnag_state {acc = queue :in (maps :merge (BaseEvent , Event ), Acc1 )});
88- send_pending (Event , # bugsnag_state {acc = Acc , acc_size = AccSize , base_event = BaseEvent } = State ) ->
87+ MergedEvent = maps :merge (BaseEvent , Event ),
88+ send_pending (State # bugsnag_state {acc = queue :in (MergedEvent , Acc1 )});
89+ maybe_send_next (
90+ Event , # bugsnag_state {acc = Acc , acc_size = AccSize , base_event = BaseEvent } = State
91+ ) ->
8992 MergedEvent = maps :merge (BaseEvent , Event ),
9093 send_pending (State # bugsnag_state {acc = queue :in (MergedEvent , Acc ), acc_size = AccSize + 1 }).
9194
@@ -97,7 +100,7 @@ send_pending(
97100) when is_integer (N ), 0 < N ->
98101 Report = BaseReport #{events := queue :to_list (Acc )},
99102 Ref = deliver_payload (ApiKey , Report , State ),
100- {noreply , State # bugsnag_state {pending = Ref , acc = queue :new ()}};
103+ {noreply , State # bugsnag_state {pending = Ref , acc = queue :new (), acc_size = 0 }};
101104send_pending (# bugsnag_state {acc_size = 0 } = State ) ->
102105 {noreply , State };
103106send_pending (# bugsnag_state {} = State ) ->
0 commit comments