Skip to content

Commit 0b106b7

Browse files
Merge pull request #108 from getsentry/hackney-opts
allow setting hackney opts
2 parents e561c8c + 156280e commit 0b106b7

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## master
4+
5+
* Enhancements
6+
* Allow setting `hackney_opts`
7+
38
## 2.1.0 (2016-12-17)
49

510
* Enhancements

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ config :sentry,
6767
| `release` | False | None | |
6868
| `server_name` | False | None | |
6969
| `use_error_logger` | False | False | |
70+
| hackney_opts | False | [] | |
7071

7172
An example production config might look like this:
7273

@@ -77,7 +78,8 @@ config :sentry,
7778
included_environments: [:prod],
7879
tags: %{
7980
env: "production"
80-
}
81+
},
82+
hackney_opts: [pool: :my_pool]
8183
```
8284

8385
The `environment_name` and `included_environments` work together to determine
@@ -111,6 +113,8 @@ Now, on our servers, we can set the environment variable appropriately. On
111113
our local development machines, exceptions will never be sent, because the
112114
default value is not in the list of `included_environments`.
113115

116+
Sentry uses the [hackney HTTP client](https://github.com/benoitc/hackney) for HTTP requests. If you need to set [hackney configurations](https://github.com/benoitc/hackney/blob/master/doc/hackney.md#request5) for things like a proxy or different pool, the `hackney_opts` configuration is passed directly to hackney.
117+
114118
## Testing Your Configuration
115119

116120
To ensure you've set up your configuration correctly we recommend running the

docs/config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Optional settings
5757
Set this to a module that implements the ``Sentry.EventFilter`` behaviour if you would like to prevent
5858
certain exceptions from being sent. See below for further documentation.
5959

60+
.. describe:: hackney_opts
61+
62+
Sentry uses `hackney <https://github.com/benoitc/hackney>`_. If you would like to set `options <https://github.com/benoitc/hackney/blob/master/doc/hackney.md#request5>`_ for hackney requests, they can be provided via this configuration.
63+
6064
Testing Your Configuration
6165
--------------------------
6266

lib/mix/tasks/sentry.send_test_event.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ defmodule Mix.Tasks.Sentry.SendTestEvent do
1818
end
1919

2020
environment_name = Application.get_env(:sentry, :environment_name)
21+
hackney_opts = Application.get_env(:sentry, :hackney_opts, [])
2122
Mix.shell.info "Client configuration:"
2223
Mix.shell.info "server: #{endpoint}"
2324
Mix.shell.info "public_key: #{public_key}"
2425
Mix.shell.info "secret_key: #{secret_key}"
2526
Mix.shell.info "included_environments: #{inspect included_environments}"
26-
Mix.shell.info "current environment_name: #{inspect environment_name}\n"
27+
Mix.shell.info "current environment_name: #{inspect environment_name}"
28+
Mix.shell.info "hackney_opts: #{inspect hackney_opts}\n"
2729

2830
maybe_send_event(environment_name, included_environments)
2931
end

lib/sentry/client.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ defmodule Sentry.Client do
4848
end
4949
end
5050

51+
@doc """
52+
Makes the HTTP request to Sentry using hackney.
53+
54+
Hackney options can be set via the `hackney_opts` configuration option.
55+
"""
5156
def request(method, url, headers, body) do
52-
case :hackney.request(method, url, headers, body, []) do
57+
hackney_opts = Application.get_env(:sentry, :hackney_opts, [])
58+
case :hackney.request(method, url, headers, body, hackney_opts) do
5359
{:ok, 200, _headers, client} ->
5460
case :hackney.body(client) do
5561
{:ok, body} ->

0 commit comments

Comments
 (0)