-
Notifications
You must be signed in to change notification settings - Fork 20
Refactor: Add ExistingTraces hook
#656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hhubert6
merged 3 commits into
main
from
654-move-existingtraces-hook-in-callback_tracing-context
Aug 7, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
lib/live_debugger_refactor/app/debugger/callback_tracing/web/hooks/existing_traces.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| defmodule LiveDebuggerRefactor.App.Debugger.CallbackTracing.Web.Hooks.ExistingTraces do | ||
| @moduledoc """ | ||
| This hook is responsible for fetching the existing traces. | ||
| """ | ||
|
|
||
| use LiveDebuggerRefactor.App.Web, :hook | ||
|
|
||
| require Logger | ||
|
|
||
| alias LiveDebuggerRefactor.API.TracesStorage | ||
| alias LiveDebuggerRefactor.App.Debugger.CallbackTracing.Structs.TraceDisplay | ||
| alias LiveDebuggerRefactor.App.Debugger.CallbackTracing.Web.Helpers.Filters, as: FiltersHelpers | ||
|
|
||
| @required_assigns [ | ||
| :lv_process, | ||
| :current_filters, | ||
| :traces_empty?, | ||
| :traces_continuation, | ||
| :existing_traces_status | ||
| ] | ||
|
|
||
| @doc """ | ||
| Initializes the hook by attaching the hook to the socket and checking the required assigns. | ||
| """ | ||
| @spec init(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t() | ||
hhubert6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def init(socket) do | ||
| socket | ||
| |> check_assigns!(@required_assigns) | ||
| |> check_stream!(:existing_traces) | ||
| |> check_private!(:page_size) | ||
| |> attach_hook(:existing_traces, :handle_async, &handle_async/3) | ||
| |> register_hook(:existing_traces) | ||
| |> assign_async_existing_traces() | ||
| end | ||
|
|
||
| @doc """ | ||
| Loads the existing traces asynchronously and assigns them to the socket. | ||
| """ | ||
| @spec assign_async_existing_traces(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t() | ||
| def assign_async_existing_traces(socket) do | ||
| pid = socket.assigns.lv_process.pid | ||
|
|
||
| opts = | ||
| [ | ||
| limit: socket.private.page_size, | ||
| functions: FiltersHelpers.get_active_functions(socket.assigns.current_filters), | ||
| execution_times: FiltersHelpers.get_execution_times(socket.assigns.current_filters), | ||
| node_id: Map.get(socket.assigns, :node_id), | ||
| search_query: Map.get(socket.assigns, :trace_search_query, "") | ||
| ] | ||
|
|
||
| start_async(socket, :fetch_existing_traces, fn -> TracesStorage.get!(pid, opts) end) | ||
| end | ||
|
|
||
| defp handle_async(:fetch_existing_traces, {:ok, {trace_list, cont}}, socket) do | ||
| trace_list = Enum.map(trace_list, &TraceDisplay.from_trace/1) | ||
|
|
||
| socket | ||
| |> assign( | ||
| existing_traces_status: :ok, | ||
| traces_empty?: false, | ||
| traces_continuation: cont | ||
| ) | ||
| |> stream(:existing_traces, trace_list, reset: true) | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_async(:fetch_existing_traces, {:ok, :end_of_table}, socket) do | ||
| socket | ||
| |> assign( | ||
| existing_traces_status: :ok, | ||
| traces_continuation: :end_of_table | ||
| ) | ||
| |> stream(:existing_traces, [], reset: true) | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_async(:fetch_existing_traces, {:exit, reason}, socket) do | ||
| Logger.error( | ||
| "LiveDebugger encountered unexpected error while fetching existing traces: #{inspect(reason)}" | ||
| ) | ||
|
|
||
| socket | ||
| |> assign(existing_traces_status: :error) | ||
| |> halt() | ||
| end | ||
|
|
||
| defp handle_async(_, _, socket), do: {:cont, socket} | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.