OeditusCredo.Check.Warning.MissingTelemetryInLiveViewMount
(OeditusCredo v0.6.1)
View Source
Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of normal and works with any version of Elixir.
Explanation
LiveView mount/3 callbacks should emit telemetry events for observability.
Instrumenting LiveView mounts helps track which LiveViews are being accessed, how long they take to initialize, and can help identify performance bottlenecks.
Bad:
defmodule MyAppWeb.DashboardLive do
use MyAppWeb, :live_view
def mount(_params, _session, socket) do
data = load_expensive_data()
{:ok, assign(socket, data: data)}
end
endGood:
defmodule MyAppWeb.DashboardLive do
use MyAppWeb, :live_view
def mount(_params, _session, socket) do
:telemetry.execute(
[:phoenix, :live_view, :mount],
%{system_time: System.system_time()},
%{module: __MODULE__}
)
data = load_expensive_data()
{:ok, assign(socket, data: data)}
end
endCheck-Specific Parameters
Use the following parameters to configure this check:
:exclude_test_files
Set to true to skip test files (default: false)
This parameter defaults to nil.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.