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 #{reclaim_max} connections"
37 [:pleroma, :connection_pool, :reclaim, :stop],
38 %{reclaimed_count: 0},
43 "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"
48 [:pleroma, :connection_pool, :reclaim, :stop],
49 %{reclaimed_count: reclaimed_count},
53 Logger.debug(fn -> "Connection pool cleaned up #{reclaimed_count} idle connections" end)
57 [:pleroma, :connection_pool, :provision_failure],
63 "Connection pool had to refuse opening a connection to #{key} due to connection limit exhaustion"
68 [:pleroma, :connection_pool, :client, :dead],
69 %{client_pid: client_pid, reason: reason},
74 "Pool worker for #{key}: Client #{inspect(client_pid)} died before releasing the connection with #{inspect(reason)}"
79 [:pleroma, :connection_pool, :client, :add],
80 %{clients: [_, _ | _] = clients},
81 %{key: key, protocol: :http},
85 "Pool worker for #{key}: #{length(clients)} clients are using an HTTP1 connection at the same time, head-of-line blocking might occur."
89 def handle_event([:pleroma, :connection_pool, :client, :add], _, _, _), do: :ok