• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supavisor / 16470769502

23 Jul 2025 12:34PM UTC coverage: 57.067% (+1.7%) from 55.355%
16470769502

Pull #694

github

web-flow
Merge 78a9c0b2c into deaa48192
Pull Request #694: feat: improved named prepared statements support

175 of 217 new or added lines in 11 files covered. (80.65%)

16 existing lines in 4 files now uncovered.

1292 of 2264 relevant lines covered (57.07%)

1126.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.25
/lib/supavisor/monitoring/telem.ex
1
defmodule Supavisor.Monitoring.Telem do
2
  @moduledoc false
3

4
  require Logger
5

6
  @disabled Application.compile_env(:supavisor, :metrics_disabled, false)
7

8
  if @disabled do
9
    defp telemetry_execute(_name, _measurements, _meta), do: :ok
10
  else
11
    defp telemetry_execute(event_name, measurements, metadata) do
12
      :telemetry.execute(event_name, measurements, metadata)
8,204✔
13
    end
14
  end
15

16
  @spec network_usage(:client | :db, Supavisor.sock(), Supavisor.id(), map()) ::
17
          {:ok | :error, map()}
18
  if @disabled do
8,500✔
19
    def network_usage(_type, _sock, _id, _stats), do: {:ok, %{recv_oct: 0, send_oct: 0}}
20
  else
21
    def network_usage(type, {mod, socket}, id, stats) do
22
      mod = if mod == :ssl, do: :ssl, else: :inet
8,500✔
23

24
      case mod.getstat(socket, [:recv_oct, :send_oct]) do
8,500✔
25
        {:ok, [{:recv_oct, recv_oct}, {:send_oct, send_oct}]} ->
26
          stats = %{
8,500✔
27
            send_oct: send_oct - Map.get(stats, :send_oct, 0),
28
            recv_oct: recv_oct - Map.get(stats, :recv_oct, 0)
29
          }
30

31
          {{ptype, tenant}, user, mode, db_name, search_path} = id
8,500✔
32

33
          :telemetry.execute(
8,500✔
34
            [:supavisor, type, :network, :stat],
35
            stats,
36
            %{
37
              tenant: tenant,
38
              user: user,
39
              mode: mode,
40
              type: ptype,
41
              db_name: db_name,
42
              search_path: search_path
43
            }
44
          )
45

46
          {:ok, %{recv_oct: recv_oct, send_oct: send_oct}}
47

48
        {:error, reason} ->
49
          Logger.error("Failed to get socket stats: #{inspect(reason)}")
×
50
          {:error, stats}
51
      end
52
    end
53
  end
54

55
  @spec pool_checkout_time(integer(), Supavisor.id(), :local | :remote) :: :ok | nil
56
  def pool_checkout_time(time, {{type, tenant}, user, mode, db_name, search_path}, same_box) do
57
    telemetry_execute(
3,524✔
58
      [:supavisor, :pool, :checkout, :stop, same_box],
59
      %{duration: time},
60
      %{
61
        tenant: tenant,
62
        user: user,
63
        mode: mode,
64
        type: type,
65
        db_name: db_name,
66
        search_path: search_path
67
      }
68
    )
69
  end
70

71
  @spec client_query_time(integer(), Supavisor.id()) :: :ok | nil
72
  def client_query_time(start, {{type, tenant}, user, mode, db_name, search_path}) do
73
    telemetry_execute(
3,425✔
74
      [:supavisor, :client, :query, :stop],
75
      %{duration: System.monotonic_time() - start},
76
      %{
77
        tenant: tenant,
78
        user: user,
79
        mode: mode,
80
        type: type,
81
        db_name: db_name,
82
        search_path: search_path
83
      }
84
    )
85
  end
86

87
  @spec client_connection_time(integer(), Supavisor.id()) :: :ok | nil
88
  def client_connection_time(start, {{type, tenant}, user, mode, db_name, search_path}) do
89
    telemetry_execute(
272✔
90
      [:supavisor, :client, :connection, :stop],
91
      %{duration: System.monotonic_time() - start},
92
      %{
93
        tenant: tenant,
94
        user: user,
95
        mode: mode,
96
        type: type,
97
        db_name: db_name,
98
        search_path: search_path
99
      }
100
    )
101
  end
102

103
  @spec client_join(:ok | :fail, Supavisor.id() | any()) :: :ok | nil
104
  def client_join(status, {{type, tenant}, user, mode, db_name, search_path}) do
105
    telemetry_execute(
580✔
106
      [:supavisor, :client, :joins, status],
107
      %{},
108
      %{
109
        tenant: tenant,
110
        user: user,
111
        mode: mode,
112
        type: type,
113
        db_name: db_name,
114
        search_path: search_path
115
      }
116
    )
117
  end
118

119
  def client_join(_status, id) do
120
    Logger.warning("client_join is called with a mismatched id: #{inspect(id)}")
3✔
121
  end
122

123
  @spec handler_action(
124
          :client_handler | :db_handler,
125
          :started | :stopped | :db_connection,
126
          Supavisor.id()
127
        ) :: :ok | nil
128
  def handler_action(handler, action, {{type, tenant}, user, mode, db_name, search_path}) do
129
    telemetry_execute(
403✔
130
      [:supavisor, handler, action, :all],
131
      %{},
132
      %{
133
        tenant: tenant,
134
        user: user,
135
        mode: mode,
136
        type: type,
137
        db_name: db_name,
138
        search_path: search_path
139
      }
140
    )
141
  end
142

143
  def handler_action(handler, action, id) do
144
    Logger.warning(
×
145
      "handler_action is called with a mismatched #{inspect(handler)} #{inspect(action)} #{inspect(id)}"
146
    )
147
  end
148

149
  def prepared_statements_evicted(count, {{type, tenant}, user, mode, db_name, search_path}) do
NEW
150
    telemetry_execute(
×
151
      [:supavisor, :db_handler, :prepared_statements, :evicted],
152
      %{count: count},
153
      %{
154
        tenant: tenant,
155
        user: user,
156
        mode: mode,
157
        type: type,
158
        db_name: db_name,
159
        search_path: search_path
160
      }
161
    )
162
  end
163
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc