1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Telemetry.Logger do
6 @moduledoc "Transforms Pleroma telemetry events to logs"
11 [:pleroma, :connection_pool, :reclaim, :start],
12 [:pleroma, :connection_pool, :reclaim, :stop],
13 [:pleroma, :connection_pool, :provision_failure],
14 [:pleroma, :connection_pool, :client, :dead],
15 [:pleroma, :connection_pool, :client, :add]
18 :telemetry.attach_many("pleroma-logger", @events, &handle_event/4, [])
21 # Passing anonymous functions instead of strings to logger is intentional,
22 # that way strings won't be concatenated if the message is going to be thrown
23 # out anyway due to higher log level configured
26 [:pleroma, :connection_pool, :reclaim, :start],
28 %{max_connections: max_connections, reclaim_max: reclaim_max},
32 "Connection pool is exhausted (reached #{max_connections} connections). Starting idle connection cleanup to reclaim as much as #{
39 [:pleroma, :connection_pool, :reclaim, :stop],
40 %{reclaimed_count: 0},
45 "Connection pool failed to reclaim any connections due to all of them being in use. It will have to drop requests for opening connections to new hosts"
50 [:pleroma, :connection_pool, :reclaim, :stop],
51 %{reclaimed_count: reclaimed_count},
55 Logger.debug(fn -> "Connection pool cleaned up #{reclaimed_count} idle connections" end)
59 [:pleroma, :connection_pool, :provision_failure],
65 "Connection pool had to refuse opening a connection to #{key} due to connection limit exhaustion"
70 [:pleroma, :connection_pool, :client, :dead],
71 %{client_pid: client_pid, reason: reason},
76 "Pool worker for #{key}: Client #{inspect(client_pid)} died before releasing the connection with #{
83 [:pleroma, :connection_pool, :client, :add],
84 %{clients: [_, _ | _] = clients},
85 %{key: key, protocol: :http},
89 "Pool worker for #{key}: #{length(clients)} clients are using an HTTP1 connection at the same time, head-of-line blocking might occur."
93 def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok