Skip to content

Commit 452b739

Browse files
committed
use module name in trace label
1 parent ebfe2d7 commit 452b739

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

lib/live_debugger_web/live/traces/components/stream.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
defmodule LiveDebuggerWeb.Live.Traces.Components.Stream do
22
@moduledoc """
33
This component is used to display the traces stream.
4-
It uses under the hood the `Trace` component to display the traces.
5-
The `Trace` component produces the `toggle-collapsible` and `trace-fullscreen` which are handled in the `Trace` component hook.
4+
It allows to compose style for the trace using `LiveDebuggerWeb.Live.Traces.Components.Trace` components.
65
"""
76

87
use LiveDebuggerWeb, :hook_component
98

10-
alias LiveDebuggerWeb.Live.Traces.Components.Trace
11-
129
@required_assigns [:id, :existing_traces_status]
1310

1411
@doc """
1512
Initializes the component by attaching the hook to the socket.
16-
Since the `Trace` component is used by this component, we need to attach the hook to the socket.
1713
"""
1814
@spec init(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
1915
def init(socket) do
2016
socket
2117
|> check_assigns!(@required_assigns)
2218
|> check_stream!(:existing_traces)
23-
|> Trace.init()
2419
|> register_hook(:traces_stream)
2520
end
2621

lib/live_debugger_web/live/traces/components/trace.ex

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
3737
attr(:id, :string, required: true)
3838
attr(:wrapped_trace, :map, required: true, doc: "The Trace to render")
3939

40+
slot :label, required: true do
41+
attr(:class, :string, doc: "Additional class for label")
42+
end
43+
4044
def trace(assigns) do
4145
assigns =
4246
assigns
@@ -51,15 +55,17 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
5155
icon="icon-chevron-right"
5256
chevron_class="w-5 h-5 text-accent-icon"
5357
class="max-w-full border border-default-border rounded last:mb-4"
54-
label_class="font-semibold bg-surface-1-bg h-10 p-2"
58+
label_class="font-semibold bg-surface-1-bg p-2 py-3"
5559
phx-click={if(@render_body?, do: nil, else: "toggle-collapsible")}
5660
phx-value-trace-id={@trace.id}
5761
>
5862
<:label>
59-
<div id={@id <> "-label"} class="w-[90%] grow flex items-center ml-2 gap-3">
60-
<p class="font-medium text-sm"><%= @callback_name %></p>
61-
<.short_trace_content trace={@trace} />
62-
<.trace_time_info id={@id} trace={@trace} from_tracing?={@from_tracing?} />
63+
<div
64+
:for={label <- @label}
65+
id={@id <> "-label"}
66+
class={["w-[90%] grow grid items-center gap-x-3 ml-2" | List.wrap(label[:class])]}
67+
>
68+
<%= render_slot(@label, assigns) %>
6369
</div>
6470
</:label>
6571
<div class="relative">
@@ -85,9 +91,29 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
8591
"""
8692
end
8793

94+
attr(:trace, Trace, required: true)
95+
attr(:class, :string, default: "")
96+
97+
def module(assigns) do
98+
~H"""
99+
<div class={["text-primary text-2xs font-normal truncate", @class]}>
100+
<%= @trace.module %>
101+
<%= if(@trace.cid, do: "(#{@trace.cid})") %>
102+
</div>
103+
"""
104+
end
105+
106+
attr(:content, :string, required: true)
107+
108+
def callback_name(assigns) do
109+
~H"""
110+
<p class="font-medium text-sm"><%= @content %></p>
111+
"""
112+
end
113+
88114
attr(:trace, :map, default: nil)
89115

90-
defp short_trace_content(assigns) do
116+
def short_trace_content(assigns) do
91117
assigns = assign(assigns, :content, Enum.map_join(assigns.trace.args, " ", &inspect/1))
92118

93119
~H"""
@@ -101,7 +127,7 @@ defmodule LiveDebuggerWeb.Live.Traces.Components.Trace do
101127
attr(:trace, :map, default: nil)
102128
attr(:from_tracing?, :boolean, default: false)
103129

104-
defp trace_time_info(assigns) do
130+
def trace_time_info(assigns) do
105131
~H"""
106132
<div class="flex text-xs font-normal text-secondary-text align-center">
107133
<.tooltip id={@id <> "-timestamp"} content="timestamp" class="min-w-24">

lib/live_debugger_web/live/traces/node_traces_live.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ defmodule LiveDebuggerWeb.Live.Traces.NodeTracesLive do
77

88
require Logger
99

10-
alias LiveDebuggerWeb.Live.Traces.Components.Trace
1110
alias LiveDebuggerWeb.Helpers.NestedLiveViewHelper
1211

1312
alias LiveDebuggerWeb.Live.Traces.Hooks
@@ -69,6 +68,7 @@ defmodule LiveDebuggerWeb.Live.Traces.NodeTracesLive do
6968
|> Helpers.assign_current_filters()
7069
|> Components.ClearButton.init()
7170
|> Components.LoadMoreButton.init(@page_size)
71+
|> Components.Trace.init()
7272
|> Components.Stream.init()
7373
|> Hooks.TracingFuse.init()
7474
|> Hooks.ExistingTraces.init(@page_size)
@@ -114,7 +114,17 @@ defmodule LiveDebuggerWeb.Live.Traces.NodeTracesLive do
114114
existing_traces={@streams.existing_traces}
115115
>
116116
<:trace :let={{id, wrapped_trace}}>
117-
<Trace.trace id={id} wrapped_trace={wrapped_trace} />
117+
<Components.Trace.trace id={id} wrapped_trace={wrapped_trace}>
118+
<:label :let={trace_assigns} class="grid-cols-[auto_1fr_auto]">
119+
<Components.Trace.callback_name content={trace_assigns.callback_name} />
120+
<Components.Trace.short_trace_content trace={trace_assigns.trace} />
121+
<Components.Trace.trace_time_info
122+
id={trace_assigns.id}
123+
trace={trace_assigns.trace}
124+
from_tracing?={trace_assigns.from_tracing?}
125+
/>
126+
</:label>
127+
</Components.Trace.trace>
118128
</:trace>
119129
</Components.Stream.traces_stream>
120130
<Components.LoadMoreButton.load_more_button

lib/live_debugger_web/live/traces/process_traces_live.ex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule LiveDebuggerWeb.Live.Traces.ProcessTracesLive do
22
use LiveDebuggerWeb, :live_view
33

4-
alias LiveDebuggerWeb.Live.Traces.Components.Trace
54
alias LiveDebuggerWeb.Live.Traces.Components
65
alias LiveDebuggerWeb.Live.Traces.Helpers
76
alias LiveDebuggerWeb.Live.Traces.Hooks
@@ -56,6 +55,7 @@ defmodule LiveDebuggerWeb.Live.Traces.ProcessTracesLive do
5655
|> Components.RefreshButton.init()
5756
|> Components.ClearButton.init()
5857
|> Components.ToggleTracingButton.init()
58+
|> Components.Trace.init()
5959
|> Components.Stream.init()
6060
|> ok()
6161
end
@@ -86,7 +86,18 @@ defmodule LiveDebuggerWeb.Live.Traces.ProcessTracesLive do
8686
existing_traces={@streams.existing_traces}
8787
>
8888
<:trace :let={{id, wrapped_trace}}>
89-
<Trace.trace id={id} wrapped_trace={wrapped_trace} />
89+
<Components.Trace.trace id={id} wrapped_trace={wrapped_trace}>
90+
<:label :let={trace_assigns} class="grid-cols-[auto_1fr_auto]">
91+
<Components.Trace.module trace={trace_assigns.trace} class="col-span-3" />
92+
<Components.Trace.callback_name content={trace_assigns.callback_name} />
93+
<Components.Trace.short_trace_content trace={trace_assigns.trace} />
94+
<Components.Trace.trace_time_info
95+
id={trace_assigns.id}
96+
trace={trace_assigns.trace}
97+
from_tracing?={trace_assigns.from_tracing?}
98+
/>
99+
</:label>
100+
</Components.Trace.trace>
90101
</:trace>
91102
</Components.Stream.traces_stream>
92103
<Components.LoadMoreButton.load_more_button

0 commit comments

Comments
 (0)