neiam
/vigil
public · Issues · Pulls · Labels · Forks · Compare · Actions running · Badges · Packages
Log in to mark this repository.
Merge branch 'worktree-agent-a52a1472f15f0d9d4'
d4408ac · gmorell · 2026-12-02 02:42
Files changed
modified
lib/vigil/performance.ex
+4
−0
| 261 | 261 | ) |
| 262 | 262 | end |
| 263 | 263 | |
| 264 | + @doc "Whether the project has ever recorded a transaction." | |
| 265 | + def any_groups?(project_id), | |
| 266 | + do: Repo.exists?(from g in TransactionGroup, where: g.project_id == ^project_id) | |
| 267 | + | |
| 264 | 268 | @doc "The trace id an issue event belongs to, or nil." |
| 265 | 269 | def trace_id_of(%IssueEvent{trace_id: id}), do: id |
| 266 | 270 |
added
lib/vigil_web/components/chart_components.ex
+118
−0
| 1 | +defmodule VigilWeb.ChartComponents do | |
| 2 | + @moduledoc """ | |
| 3 | + The app's one chart form: a single-series bar chart drawn in HTML. | |
| 4 | + | |
| 5 | + One series, so no legend: the surrounding section's title names it. Thin | |
| 6 | + bars in the theme's primary, 4px rounded tops anchored to the baseline, a | |
| 7 | + 2px gap between bars; a recessive axis (the peak and three marks along | |
| 8 | + the bottom); a hover tooltip per bar with a hit target the full column | |
| 9 | + tall; and the same numbers as a table (`Show as a table`) for screen | |
| 10 | + readers and anyone who wants them. No JS. | |
| 11 | + """ | |
| 12 | + use Phoenix.Component | |
| 13 | + | |
| 14 | + @doc """ | |
| 15 | + Bars for `points`, each `%{value:, tip:, axis:, row:}`: `tip` is the | |
| 16 | + tooltip's text after the value, `axis` the short label used for the | |
| 17 | + three axis marks, `row` the table's first column. DOM ids hang off `id`: | |
| 18 | + `<id>-bars`, `<id>-bar-<i>`, `<id>-table`. | |
| 19 | + """ | |
| 20 | + attr :id, :string, required: true | |
| 21 | + attr :points, :list, required: true | |
| 22 | + attr :label, :string, required: true, doc: "what the chart shows, for its aria-label" | |
| 23 | + attr :key_header, :string, required: true | |
| 24 | + attr :value_header, :string, required: true | |
| 25 | + attr :format, :any, default: &__MODULE__.format_count/1 | |
| 26 | + attr :class, :string, default: "h-32" | |
| 27 | + | |
| 28 | + def bars(assigns) do | |
| 29 | + max = assigns.points |> Enum.map(& &1.value) |> Enum.max(fn -> 0 end) | |
| 30 | + assigns = assign(assigns, max: max, marks: axis_marks(assigns.points)) | |
| 31 | + | |
| 32 | + ~H""" | |
| 33 | + <div class="mt-4"> | |
| 34 | + <div | |
| 35 | + class={["relative", @class]} | |
| 36 | + role="img" | |
| 37 | + aria-label={"#{@label}, peak #{@format.(@max)}"} | |
| 38 | + > | |
| 39 | + <div class="absolute inset-x-0 bottom-0 border-t border-base-300" aria-hidden="true" /> | |
| 40 | + <span | |
| 41 | + :if={@max > 0} | |
| 42 | + class="absolute -top-1 right-0 text-[0.65rem] tabular-nums text-base-content/50" | |
| 43 | + aria-hidden="true" | |
| 44 | + > | |
| 45 | + {@format.(@max)} | |
| 46 | + </span> | |
| 47 | + <div class="flex h-full items-end gap-[2px]" id={"#{@id}-bars"}> | |
| 48 | + <div | |
| 49 | + :for={{p, i} <- Enum.with_index(@points)} | |
| 50 | + id={"#{@id}-bar-#{i}"} | |
| 51 | + class="group relative flex h-full flex-1 items-end" | |
| 52 | + > | |
| 53 | + <div | |
| 54 | + class={[ | |
| 55 | + "w-full rounded-t-[4px] transition-colors", | |
| 56 | + if(p.value > 0, | |
| 57 | + do: "bg-primary group-hover:bg-primary/80", | |
| 58 | + else: "bg-base-300/60" | |
| 59 | + ) | |
| 60 | + ]} | |
| 61 | + style={"height: #{bar_height(p.value, @max)}"} | |
| 62 | + /> | |
| 63 | + <div class="pointer-events-none absolute bottom-full left-1/2 z-10 mb-1 hidden -translate-x-1/2 whitespace-nowrap rounded-box border border-base-300 bg-base-100 px-2 py-1 text-xs shadow-md group-hover:block"> | |
| 64 | + <span class="font-semibold tabular-nums">{@format.(p.value)}</span> {p.tip} | |
| 65 | + </div> | |
| 66 | + </div> | |
| 67 | + </div> | |
| 68 | + </div> | |
| 69 | + <div class="mt-1 flex justify-between text-[0.65rem] text-base-content/50" aria-hidden="true"> | |
| 70 | + <span :for={p <- @marks}>{p.axis}</span> | |
| 71 | + </div> | |
| 72 | + <details class="mt-2 text-xs text-base-content/60"> | |
| 73 | + <summary class="cursor-pointer">Show as a table</summary> | |
| 74 | + <table id={"#{@id}-table"} class="table table-xs mt-2"> | |
| 75 | + <thead> | |
| 76 | + <tr> | |
| 77 | + <th>{@key_header}</th><th class="text-right">{@value_header}</th> | |
| 78 | + </tr> | |
| 79 | + </thead> | |
| 80 | + <tbody> | |
| 81 | + <tr :for={p <- @points}> | |
| 82 | + <td>{p.row}</td> | |
| 83 | + <td class="text-right tabular-nums">{@format.(p.value)}</td> | |
| 84 | + </tr> | |
| 85 | + </tbody> | |
| 86 | + </table> | |
| 87 | + </details> | |
| 88 | + </div> | |
| 89 | + """ | |
| 90 | + end | |
| 91 | + | |
| 92 | + @doc "Hourly `{hour, count}` pairs as `bars/1` points." | |
| 93 | + def hourly_points(hourly) do | |
| 94 | + for {hour, n} <- hourly do | |
| 95 | + %{ | |
| 96 | + value: n, | |
| 97 | + tip: "at #{Calendar.strftime(hour, "%H:00")} UTC", | |
| 98 | + axis: Calendar.strftime(hour, "%H:00"), | |
| 99 | + row: Calendar.strftime(hour, "%Y-%m-%d %H:00") | |
| 100 | + } | |
| 101 | + end | |
| 102 | + end | |
| 103 | + | |
| 104 | + defp bar_height(n, _max) when n <= 0, do: "2px" | |
| 105 | + defp bar_height(n, max), do: "max(3px, #{Float.round(n / max * 100, 2)}%)" | |
| 106 | + | |
| 107 | + defp axis_marks([]), do: [] | |
| 108 | + | |
| 109 | + defp axis_marks(points) do | |
| 110 | + n = length(points) | |
| 111 | + [Enum.at(points, 0), Enum.at(points, div(n, 2)), List.last(points)] | |
| 112 | + end | |
| 113 | + | |
| 114 | + @doc "A count, compacted for an axis or tooltip: 12, 12k, 1.2M." | |
| 115 | + def format_count(n) when n >= 1_000_000, do: "#{Float.round(n / 1_000_000, 1)}M" | |
| 116 | + def format_count(n) when n >= 10_000, do: "#{div(n, 1000)}k" | |
| 117 | + def format_count(n), do: to_string(n) | |
| 118 | +end |
added
lib/vigil_web/components/performance_components.ex
+75
−0
| 1 | +defmodule VigilWeb.PerformanceComponents do | |
| 2 | + @moduledoc """ | |
| 3 | + Pieces the performance pages share: duration, throughput and error-rate | |
| 4 | + formatting, a transaction's op and method badges, and a stat tile. | |
| 5 | + """ | |
| 6 | + use Phoenix.Component | |
| 7 | + | |
| 8 | + @doc "A duration in ms for people: 850µs, 4.2ms, 120ms, 1.35s, 2m 5s; nil is a dash." | |
| 9 | + def duration(nil), do: "—" | |
| 10 | + def duration(ms) when ms < 1, do: "#{round(ms * 1000)}µs" | |
| 11 | + def duration(ms) when ms < 10, do: "#{:erlang.float_to_binary(ms / 1, decimals: 1)}ms" | |
| 12 | + def duration(ms) when ms < 1000, do: "#{round(ms)}ms" | |
| 13 | + | |
| 14 | + def duration(ms) when ms < 60_000, | |
| 15 | + do: "#{:erlang.float_to_binary(ms / 1000, decimals: if(ms < 10_000, do: 2, else: 1))}s" | |
| 16 | + | |
| 17 | + def duration(ms) do | |
| 18 | + s = round(ms / 1000) | |
| 19 | + "#{div(s, 60)}m #{rem(s, 60)}s" | |
| 20 | + end | |
| 21 | + | |
| 22 | + @doc "Transactions a minute: 0, <0.01, 0.42, 12.3, 120." | |
| 23 | + def tpm(t) when t == 0, do: "0" | |
| 24 | + def tpm(t) when t < 0.01, do: "<0.01" | |
| 25 | + def tpm(t) when t < 10, do: :erlang.float_to_binary(t / 1, decimals: 2) | |
| 26 | + def tpm(t) when t < 100, do: :erlang.float_to_binary(t / 1, decimals: 1) | |
| 27 | + def tpm(t), do: Integer.to_string(round(t)) | |
| 28 | + | |
| 29 | + @doc "An error rate (0..1) as a percentage." | |
| 30 | + def rate(r) when r == 0, do: "0%" | |
| 31 | + def rate(r) when r < 0.001, do: "<0.1%" | |
| 32 | + def rate(r), do: "#{:erlang.float_to_binary(r * 100, decimals: 1)}%" | |
| 33 | + | |
| 34 | + @doc "Whether a span's status means it failed." | |
| 35 | + def failed?(status), do: status not in [nil, "", "ok", "unset"] | |
| 36 | + | |
| 37 | + attr :group, :map, required: true | |
| 38 | + | |
| 39 | + @doc "A transaction group's method and op, as small badges." | |
| 40 | + def txn_badges(assigns) do | |
| 41 | + ~H""" | |
| 42 | + <span | |
| 43 | + :if={@group.method not in [nil, ""]} | |
| 44 | + class="badge badge-outline badge-xs font-mono" | |
| 45 | + > | |
| 46 | + {@group.method} | |
| 47 | + </span> | |
| 48 | + <span :if={@group.op not in [nil, ""]} class="badge badge-ghost badge-xs font-mono"> | |
| 49 | + {@group.op} | |
| 50 | + </span> | |
| 51 | + """ | |
| 52 | + end | |
| 53 | + | |
| 54 | + attr :id, :string, required: true | |
| 55 | + attr :label, :string, required: true | |
| 56 | + attr :hint, :string, default: nil | |
| 57 | + attr :tone, :atom, default: nil, values: [nil, :error] | |
| 58 | + slot :inner_block, required: true | |
| 59 | + | |
| 60 | + @doc "A stat tile." | |
| 61 | + def stat(assigns) do | |
| 62 | + ~H""" | |
| 63 | + <div | |
| 64 | + id={@id} | |
| 65 | + class="rounded-box border border-base-300 bg-base-100 px-4 py-3 transition hover:border-base-content/20" | |
| 66 | + title={@hint} | |
| 67 | + > | |
| 68 | + <dt class="text-xs font-medium uppercase tracking-wide text-base-content/60">{@label}</dt> | |
| 69 | + <dd class={["mt-1 text-lg font-semibold tabular-nums", @tone == :error && "text-error"]}> | |
| 70 | + {render_slot(@inner_block)} | |
| 71 | + </dd> | |
| 72 | + </div> | |
| 73 | + """ | |
| 74 | + end | |
| 75 | +end |
modified
lib/vigil_web/live/issue_live/index.ex
+9
−0
| 233 | 233 | > |
| 234 | 234 | <.icon name="hero-rocket-launch-micro" class="size-4" /> Releases |
| 235 | 235 | </.link> |
| 236 | + <.link | |
| 237 | + navigate={ | |
| 238 | + ~p"/orgs/#{@current_scope.organization.slug}/projects/#{@project.slug}/performance" | |
| 239 | + } | |
| 240 | + class="btn btn-ghost btn-sm" | |
| 241 | + id="project-performance" | |
| 242 | + > | |
| 243 | + <.icon name="hero-bolt-micro" class="size-4" /> Performance | |
| 244 | + </.link> | |
| 236 | 245 | <.link |
| 237 | 246 | :if={Scope.can?(@current_scope, "project:write")} |
| 238 | 247 | navigate={ |
modified
lib/vigil_web/live/issue_live/show.ex
+23
−1
| 22 | 22 | import VigilWeb.EventComponents |
| 23 | 23 | |
| 24 | 24 | alias Vigil.Accounts.Scope |
| 25 | − alias Vigil.Issues | |
| 25 | + alias Vigil.{Issues, Performance, Projects} | |
| 26 | 26 | |
| 27 | 27 | @impl true |
| 28 | 28 | def mount(%{"short_id" => short_id}, _session, socket) do |
| 48 | 48 | |> assign(:assignable, Issues.assignable_users(scope.organization.id)) |
| 49 | 49 | |> assign(:new_events, 0) |
| 50 | 50 | |> assign(:event, nil) |
| 51 | + |> assign(:trace_path, nil) | |
| 51 | 52 | |> assign(:nav, nil) |
| 52 | 53 | |> assign(:comment_form, to_form(Issues.change_comment())) |
| 53 | 54 | |> load_issue(issue) |
| 73 | 74 | {:noreply, |
| 74 | 75 | socket |
| 75 | 76 | |> assign(:event, event) |
| 77 | + |> assign(:trace_path, trace_path(socket.assigns.current_scope, event)) | |
| 76 | 78 | |> assign(:nav, Issues.event_nav(issue, event)) |
| 77 | 79 | |> then(&if(&1.assigns.nav.newer, do: &1, else: assign(&1, :new_events, 0)))} |
| 78 | 80 |
| 152 | 154 | do: |
| 153 | 155 | ~p"/orgs/#{scope.organization.slug}/projects/#{project.slug}/issues/#{issue.short_id}/events/#{event_id}" |
| 154 | 156 | |
| 157 | + # The event's trace, when spans of it are kept in a project the caller sees. | |
| 158 | + defp trace_path(_scope, %{trace_id: nil}), do: nil | |
| 159 | + | |
| 160 | + defp trace_path(scope, %{trace_id: trace_id}) do | |
| 161 | + ids = scope |> Projects.list_visible() |> Enum.map(& &1.id) | |
| 162 | + | |
| 163 | + if Performance.trace_exists?(ids, trace_id), | |
| 164 | + do: ~p"/orgs/#{scope.organization.slug}/traces/#{trace_id}" | |
| 165 | + end | |
| 166 | + | |
| 155 | 167 | defp short_id(project, issue), do: "#{String.upcase(project.slug)}-#{issue.short_id}" |
| 156 | 168 | |
| 157 | 169 | ## Render |
| 228 | 240 | event={@event} |
| 229 | 241 | nav={@nav} |
| 230 | 242 | new_events={@new_events} |
| 243 | + trace_path={@trace_path} | |
| 231 | 244 | newest_path={issue_path(@current_scope, @project, @issue)} |
| 232 | 245 | path={&event_path(@current_scope, @project, @issue, &1)} |
| 233 | 246 | /> |
| 545 | 558 | attr :event, :map, required: true |
| 546 | 559 | attr :nav, :map, required: true |
| 547 | 560 | attr :new_events, :integer, required: true |
| 561 | + attr :trace_path, :string, default: nil | |
| 548 | 562 | attr :newest_path, :string, required: true |
| 549 | 563 | attr :path, :any, required: true |
| 550 | 564 |
| 577 | 591 | <span :if={@event.environment} class="inline-flex items-center gap-1"> |
| 578 | 592 | <.icon name="hero-server-micro" class="size-3" />{@event.environment} |
| 579 | 593 | </span> |
| 594 | + <.link | |
| 595 | + :if={@trace_path} | |
| 596 | + navigate={@trace_path} | |
| 597 | + id="view-trace" | |
| 598 | + class="inline-flex items-center gap-1 font-medium text-primary transition hover:underline" | |
| 599 | + > | |
| 600 | + <.icon name="hero-bars-3-bottom-left-micro" class="size-3" /> View trace | |
| 601 | + </.link> | |
| 580 | 602 | </p> |
| 581 | 603 | </div> |
| 582 | 604 | <div class="join"> |
modified
lib/vigil_web/live/org_live/show.ex
+9
−84
Click to load diff…
added
lib/vigil_web/live/performance_live/index.ex
+283
−0
Click to load diff…
added
lib/vigil_web/live/performance_live/show.ex
+300
−0
Click to load diff…
added
lib/vigil_web/live/trace_live/show.ex
+332
−0
Click to load diff…
modified
lib/vigil_web/router.ex
+4
−0
Click to load diff…
added
test/support/fixtures/performance_fixtures.ex
+100
−0
Click to load diff…
modified
test/vigil_web/ingest_plug_test.exs
+4
−2
Click to load diff…
added
test/vigil_web/live/issue_live/view_trace_test.exs
+40
−0
Click to load diff…
added
test/vigil_web/live/performance_live_test.exs
+151
−0
Click to load diff…
added
test/vigil_web/live/trace_live_test.exs
+90
−0
Click to load diff…