Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/posthog/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ defmodule PostHog.Handler do
defp do_type(%{meta: %{crash_reason: {reason, _}}}),
do: Exception.format_banner(:exit, reason)

defp do_type(%{msg: {:string, chardata}}), do: IO.iodata_to_binary(chardata)
defp do_type(%{msg: {:string, chardata}}), do: IO.chardata_to_string(chardata)

defp do_type(%{msg: {:report, report}, meta: %{report_cb: report_cb}})
when is_function(report_cb, 1) do
{io_format, data} = report_cb.(report)

io_format
|> :io_lib.format(data)
|> IO.iodata_to_binary()
|> IO.chardata_to_string()
end

defp do_type(%{msg: {:report, report}}), do: inspect(report)

defp do_type(%{msg: {io_format, data}}),
do: io_format |> :io_lib.format(data) |> IO.iodata_to_binary()
do: io_format |> :io_lib.format(data) |> IO.chardata_to_string()

defp value(%{meta: %{crash_reason: {reason, stacktrace}}}) when is_exception(reason),
do: %{value: Exception.format_banner(:error, reason, stacktrace)}
Expand All @@ -106,18 +106,18 @@ defmodule PostHog.Handler do
defp value(%{meta: %{crash_reason: {reason, stacktrace}}}),
do: %{value: Exception.format_banner(:exit, reason, stacktrace)}

defp value(%{msg: {:string, chardata}}), do: %{value: IO.iodata_to_binary(chardata)}
defp value(%{msg: {:string, chardata}}), do: %{value: IO.chardata_to_string(chardata)}

defp value(%{msg: {:report, report}, meta: %{report_cb: report_cb}})
when is_function(report_cb, 1) do
{io_format, data} = report_cb.(report)
io_format |> :io_lib.format(data) |> IO.iodata_to_binary() |> then(&%{value: &1})
io_format |> :io_lib.format(data) |> IO.chardata_to_string() |> then(&%{value: &1})
end

defp value(%{msg: {:report, report}}), do: %{value: inspect(report)}

defp value(%{msg: {io_format, data}}),
do: io_format |> :io_lib.format(data) |> IO.iodata_to_binary() |> then(&%{value: &1})
do: io_format |> :io_lib.format(data) |> IO.chardata_to_string() |> then(&%{value: &1})

defp stacktrace(%{meta: %{crash_reason: {_reason, [_ | _] = stacktrace}}}, in_app_modules) do
frames =
Expand Down
23 changes: 23 additions & 0 deletions test/posthog/handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,29 @@ defmodule PostHog.HandlerTest do
} = event
end

test "chardata message - emoji", %{
handler_ref: ref,
config: %{supervisor_name: supervisor_name}
} do
Logger.bare_log(:info, [?H, ["ello", []], 32, ~c"World 🪩"])
LoggerHandlerKit.Assert.assert_logged(ref)

assert [event] = all_captured(supervisor_name)

assert %{
event: "$exception",
properties: %{
"$exception_list": [
%{
type: "Hello World 🪩",
value: "Hello World 🪩",
mechanism: %{handled: true}
}
]
}
} = event
end

test "chardata message - improper", %{
handler_ref: ref,
config: %{supervisor_name: supervisor_name}
Expand Down
Loading