Skip to content

Commit 6af2a79

Browse files
committed
update HTTPClient docs
1 parent 4cd8fb9 commit 6af2a79

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

lib/sentry/hackney_client.ex

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
defmodule Sentry.HackneyClient do
2+
@behaviour Sentry.HTTPClient
3+
4+
@moduledoc """
5+
The built-in HTTP client.
6+
"""
7+
8+
@hackney_pool_name :sentry_pool
9+
10+
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+
22+
:hackney_pool.child_spec(
23+
@hackney_pool_name,
24+
timeout: Sentry.Config.hackney_timeout(),
25+
max_connections: Sentry.Config.max_hackney_connections()
26+
)
27+
end
28+
29+
def post(url, headers, body) do
30+
hackney_opts =
31+
Sentry.Config.hackney_opts()
32+
|> Keyword.put_new(:pool, @hackney_pool_name)
33+
34+
with {:ok, status, headers, client} <-
35+
:hackney.request(:post, url, headers, body, hackney_opts),
36+
{:ok, body} <- :hackney.body(client) do
37+
{:ok, status, headers, body}
38+
end
39+
end
40+
end

lib/sentry/http_client.ex

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
defmodule Sentry.HTTPClient do
22
@moduledoc """
33
Specifies the API for using a custom HTTP Client.
4+
5+
The default HTTP client is `Sentry.HackneyClient`
6+
7+
To configure a different HTTP client, implement the `Sentry.HTTPClient` behaviour and
8+
change the `:client` configuration:
9+
10+
config :sentry,
11+
client: MyHTTPClient
412
"""
513

614
@type headers :: [{String.t(), String.t()}]
@@ -11,44 +19,3 @@ defmodule Sentry.HTTPClient do
1119
{:ok, status :: pos_integer, headers, body :: String.t()}
1220
| {:error, term}
1321
end
14-
15-
defmodule Sentry.HackneyClient do
16-
@behaviour Sentry.HTTPClient
17-
18-
@moduledoc """
19-
The built-in HTTP client.
20-
"""
21-
22-
@hackney_pool_name :sentry_pool
23-
24-
def child_spec do
25-
unless Code.ensure_loaded?(:hackney) do
26-
raise """
27-
cannot start Sentry.HackneyClient because :hackney is not available.
28-
Please make sure to add hackney as a dependency:
29-
30-
{:hackney, "~> 1.8"}
31-
"""
32-
end
33-
34-
Application.ensure_all_started(:hackney)
35-
36-
:hackney_pool.child_spec(
37-
@hackney_pool_name,
38-
timeout: Sentry.Config.hackney_timeout(),
39-
max_connections: Sentry.Config.max_hackney_connections()
40-
)
41-
end
42-
43-
def post(url, headers, body) do
44-
hackney_opts =
45-
Sentry.Config.hackney_opts()
46-
|> Keyword.put_new(:pool, @hackney_pool_name)
47-
48-
with {:ok, status, headers, client} <-
49-
:hackney.request(:post, url, headers, body, hackney_opts),
50-
{:ok, body} <- :hackney.body(client) do
51-
{:ok, status, headers, body}
52-
end
53-
end
54-
end

0 commit comments

Comments
 (0)