Skip to content

Commit 43e104e

Browse files
authored
Check :hackney application when starting (#554)
1 parent b257146 commit 43e104e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lib/sentry.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ defmodule Sentry do
101101
Config.client().child_spec()
102102
]
103103

104+
if Config.client() == Sentry.HackneyClient do
105+
unless Code.ensure_loaded?(:hackney) do
106+
raise """
107+
cannot start the :sentry application because the HTTP client is set to \
108+
Sentry.HackneyClient (which is the default), but the Hackney library is not loaded. \
109+
Add :hackney to your dependencies to fix this.
110+
"""
111+
end
112+
113+
case Application.ensure_all_started(:hackney) do
114+
{:ok, _apps} -> :ok
115+
{:error, reason} -> raise "failed to start the :hackney application: #{inspect(reason)}"
116+
end
117+
end
118+
104119
validate_json_config!()
105120
validate_log_level_config!()
106121

lib/sentry/hackney_client.ex

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,16 @@ defmodule Sentry.HackneyClient do
77

88
@hackney_pool_name :sentry_pool
99

10+
@impl true
1011
def child_spec do
11-
unless Code.ensure_loaded?(:hackney) do
12-
raise """
13-
cannot start Sentry.HackneyClient because :hackney is not available.
14-
Please make sure to add hackney as a dependency:
15-
16-
{:hackney, "~> 1.8"}
17-
"""
18-
end
19-
20-
Application.ensure_all_started(:hackney)
21-
2212
:hackney_pool.child_spec(
2313
@hackney_pool_name,
2414
timeout: Sentry.Config.hackney_timeout(),
2515
max_connections: Sentry.Config.max_hackney_connections()
2616
)
2717
end
2818

19+
@impl true
2920
def post(url, headers, body) do
3021
hackney_opts =
3122
Sentry.Config.hackney_opts()

0 commit comments

Comments
 (0)