Skip to content

Commit

Permalink
Add initial missing telemetry spans for live component updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Nezteb committed Oct 14, 2024
1 parent ebca5e7 commit 9073648
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
31 changes: 27 additions & 4 deletions lib/phoenix_live_view/diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,19 @@ defmodule Phoenix.LiveView.Diff do

{diff, new_components, :noop} =
write_component(socket, cid, components, fn component_socket, component ->
{Utils.maybe_call_update!(component_socket, component, updated_assigns), :noop}
telemetry_metadata = %{
socket: component_socket,
component: component,
assigns_sockets: updated_assigns
}

sockets =
:telemetry.span([:phoenix, :live_component, :update], telemetry_metadata, fn ->
{Utils.maybe_call_update!(component_socket, component, updated_assigns),
telemetry_metadata}
end)

{sockets, :noop}
end)

{diff, new_components}
Expand Down Expand Up @@ -326,9 +338,20 @@ defmodule Phoenix.LiveView.Diff do
socket = mount_component(socket, component, mount_assigns)
assigns = maybe_call_preload!(component, assigns)

socket
|> Utils.maybe_call_update!(component, assigns)
|> component_to_rendered(component, assigns[:id])
telemetry_metadata = %{
socket: socket,
component: component,
assigns_sockets: assigns
}

:telemetry.span([:phoenix, :live_component, :update], telemetry_metadata, fn ->
result =
socket
|> Utils.maybe_call_update!(component, assigns)
|> component_to_rendered(component, assigns[:id])

{result, telemetry_metadata}
end)
end

defp component_to_rendered(socket, component, id) do
Expand Down
17 changes: 9 additions & 8 deletions lib/phoenix_live_view/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ defmodule Phoenix.LiveView.Rendered do

@type t :: %__MODULE__{
static: [String.t()],
dynamic: (boolean() ->
[
nil
| iodata()
| Phoenix.LiveView.Rendered.t()
| Phoenix.LiveView.Comprehension.t()
| Phoenix.LiveView.Component.t()
]),
dynamic:
(boolean() ->
[
nil
| iodata()
| Phoenix.LiveView.Rendered.t()
| Phoenix.LiveView.Comprehension.t()
| Phoenix.LiveView.Component.t()
]),
fingerprint: integer(),
root: nil | true | false,
caller:
Expand Down
5 changes: 3 additions & 2 deletions lib/phoenix_live_view/upload_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ defmodule Phoenix.LiveView.UploadConfig do
errors: list(),
ref: String.t(),
auto_upload?: boolean(),
writer: (name :: atom() | String.t(), UploadEntry.t(), Phoenix.LiveView.Socket.t() ->
{module(), term()}),
writer:
(name :: atom() | String.t(), UploadEntry.t(), Phoenix.LiveView.Socket.t() ->
{module(), term()}),
progress_event:
(name :: atom() | String.t(), UploadEntry.t(), Phoenix.LiveView.Socket.t() ->
{:noreply, Phoenix.LiveView.Socket.t()})
Expand Down

0 comments on commit 9073648

Please sign in to comment.