Phoenix.LiveDashboard.TelemetryListener Enum.EmptyError
timgent opened this issue · comments
Tim Gent commented
Environment
Make sure you are using the latest LiveView and Dashboard versions before continuing.
- Elixir version (elixir -v): 1.13.1-otp-24
- Phoenix version (mix deps):
- Phoenix LiveView version (mix deps): 0.17.5
- Phoenix Dashboard version (mix deps): 0.6.2
- Operating system: Alpine
- Browsers you attempted to reproduce this bug on (the more the merrier): n/a
Actual behavior
We've got some errors from our application with this stacktrace. Unfortunately it's hard to track down exactly what led to this:
Handler {Phoenix.LiveDashboard.TelemetryListener, [:phoenix, :endpoint, :stop],
#PID<0.6696.0>} has failed and has been detached. Class=:error
Reason=%Enum.EmptyError{message: "empty error"}
Stacktrace=[
{Enum, :reduce, 2,
[file: 'lib/enum.ex', line: 2342, error_info: %{module: Exception}]},
{Phoenix.LiveDashboard.TelemetryListener, :tags_to_label, 2,
[file: 'lib/phoenix/live_dashboard/telemetry_listener.ex', line: 66]},
{Phoenix.LiveDashboard.TelemetryListener, :extract_datapoint_f
Looking at this code in live_dashboard it appears that we would get this error if:
- We receive non-empty tags
- The tag_values map doesn't contain any of the items in tags
- So the first reduce returns an empty list
- The second reduce would then fail
defp tags_to_label(%{tags: []}, _metadata), do: nil
defp tags_to_label(%{tags: tags, tag_values: tag_values}, metadata) do
tag_values = tag_values.(metadata)
tags
|> Enum.reduce([], fn tag, acc ->
case tag_values do
%{^tag => value} -> [to_string(value) | acc]
%{} -> acc
end
end)
|> Enum.reduce(&[&1, " " | &2])
|> IO.iodata_to_binary()
end
I've not dug into what this code is doing and how it's consumed. It could simply be a case of adding a default accumulator (empty list) to the second reduce function. Thoughts appreciated!
Expected behavior
These errors to not be thrown
Tim Gent commented
Thanks for the insanely fast fix!