Skip to content

Commit

Permalink
feat: added customer encoder using OTP27 json (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rcq authored Feb 14, 2025
1 parent 4bd2bdd commit c35a0d2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/bugsnag.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.

% Internal API

encoder([{_, _} | _] = Value, Encode) -> json:encode_key_value_list(Value, Encode);
encoder(Other, Encode) -> json:encode_value(Other, Encode).

custom_encode(Value) -> json:encode(Value, fun(Value, Encode) -> encoder(Value, Encode) end).

% See https://docs.bugsnag.com/api/error-reporting/#api-reference
send_exception(_Type, Reason, Message, _Module, _Line, Trace, _Request, State) ->
Payload = [
Expand Down Expand Up @@ -88,7 +94,7 @@ send_exception(_Type, Reason, Message, _Module, _Line, Trace, _Request, State) -
]
]}
],
deliver_payload(json:encode(Payload)).
deliver_payload(iolist_to_binary(custom_encode(Payload))).

process_trace(Trace) ->
lager:info("Processing trace ~p", [Trace]),
Expand Down

0 comments on commit c35a0d2

Please sign in to comment.