-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch HTTP client from hackney to finch #758
base: master
Are you sure you want to change the base?
Changes from all commits
fb76cdd
3bb8a51
357fa08
ebe8186
5602bac
ce54a5d
9eddb76
11f2d52
26f6c73
56aa853
9a5d14a
1d61bf4
8f3fc16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/_build | ||
/.elixir_ls | ||
/deps | ||
erl_crash.dump | ||
*.ez | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,11 +284,11 @@ defmodule Sentry.Config do | |
client: [ | ||
type: :atom, | ||
type_doc: "`t:module/0`", | ||
default: Sentry.HackneyClient, | ||
default: Sentry.FinchClient, | ||
doc: """ | ||
A module that implements the `Sentry.HTTPClient` | ||
behaviour. Defaults to `Sentry.HackneyClient`, which uses | ||
[hackney](https://github.com/benoitc/hackney) as the HTTP client. | ||
behaviour. Defaults to `Sentry.FinchClient`, which uses | ||
[Finch](https://github.com/sneako/finch) as the HTTP client. | ||
""" | ||
], | ||
send_max_attempts: [ | ||
|
@@ -298,32 +298,64 @@ defmodule Sentry.Config do | |
The maximum number of attempts to send an event to Sentry. | ||
""" | ||
], | ||
hackney_opts: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to keep This also applies to the options below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean we need to keep the option: client: [
type: :atom,
type_doc: "`t:module/0`",
default: Sentry.HackneyClient,
doc: """
"""
] and the module HackneyClient?? @whatyouhide |
||
finch_opts: [ | ||
type: :keyword_list, | ||
default: [pool: :sentry_pool], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @jjcarstens for the review 💜 You're right! :sentry_pool isn't valid. The Finch config options were just placeholder until we decide what options to expose. Which of the pool options do we want to support? @whatyouhide or @jjcarstens thoughts? finch_pool_opts: [
type: :keyword_list,
default: [size: 50, conn_max_idle_time: 5000],
doc: """
Start link pool ptions to be passed to `finch`....
"""
] |
||
doc: """ | ||
Options to be passed to `hackney`. Only | ||
applied if `:client` is set to `Sentry.HackneyClient`. | ||
Options to be passed to `finch`. Only | ||
applied if `:client` is set to `Sentry.FinchClient`. | ||
""" | ||
], | ||
hackney_pool_timeout: [ | ||
finch_pool_timeout: [ | ||
type: :timeout, | ||
default: 5000, | ||
doc: """ | ||
The maximum time to wait for a | ||
connection to become available. Only applied if `:client` is set to | ||
`Sentry.HackneyClient`. | ||
`Sentry.FinchClient`. | ||
""" | ||
], | ||
hackney_pool_max_connections: [ | ||
finch_pool_max_connections: [ | ||
type: :pos_integer, | ||
default: 50, | ||
doc: """ | ||
The maximum number of | ||
connections to keep in the pool. Only applied if `:client` is set to | ||
`Sentry.HackneyClient`. | ||
`Sentry.FinchClient`. | ||
""" | ||
] | ||
], | ||
hackney_opts: | ||
[ | ||
type: :keyword_list, | ||
default: [pool: :sentry_pool], | ||
doc: """ | ||
Options to be passed to `hackney`. Only | ||
applied if `:client` is set to `Sentry.HackneyClient`. | ||
""" | ||
] ++ | ||
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]), | ||
hackney_pool_timeout: | ||
[ | ||
type: :timeout, | ||
default: 5000, | ||
doc: """ | ||
The maximum time to wait for a | ||
connection to become available. Only applied if `:client` is set to | ||
`Sentry.HackneyClient`. | ||
""" | ||
] ++ | ||
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]), | ||
hackney_pool_max_connections: | ||
[ | ||
type: :pos_integer, | ||
default: 50, | ||
doc: """ | ||
The maximum number of | ||
connections to keep in the pool. Only applied if `:client` is set to | ||
`Sentry.HackneyClient`. | ||
""" | ||
] ++ | ||
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]) | ||
] | ||
|
||
source_code_context_opts_schema = [ | ||
|
@@ -545,11 +577,11 @@ defmodule Sentry.Config do | |
@spec environment_name() :: String.t() | nil | ||
def environment_name, do: fetch!(:environment_name) | ||
|
||
@spec max_hackney_connections() :: pos_integer() | ||
def max_hackney_connections, do: fetch!(:hackney_pool_max_connections) | ||
@spec max_finch_connections() :: pos_integer() | ||
def max_finch_connections, do: fetch!(:finch_pool_max_connections) | ||
|
||
@spec hackney_timeout() :: timeout() | ||
def hackney_timeout, do: fetch!(:hackney_pool_timeout) | ||
@spec finch_timeout() :: timeout() | ||
def finch_timeout, do: fetch!(:finch_pool_timeout) | ||
|
||
@spec tags() :: map() | ||
def tags, do: fetch!(:tags) | ||
|
@@ -590,8 +622,8 @@ defmodule Sentry.Config do | |
@spec sample_rate() :: float() | ||
def sample_rate, do: fetch!(:sample_rate) | ||
|
||
@spec hackney_opts() :: keyword() | ||
def hackney_opts, do: fetch!(:hackney_opts) | ||
@spec finch_opts() :: keyword() | ||
def finch_opts, do: fetch!(:finch_opts) | ||
Comment on lines
+625
to
+626
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we use these? |
||
|
||
@spec before_send() :: (Sentry.Event.t() -> Sentry.Event.t()) | {module(), atom()} | nil | ||
def before_send, do: get(:before_send) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
defmodule Sentry.FinchClient do | ||
@behaviour Sentry.HTTPClient | ||
|
||
@moduledoc """ | ||
The built-in HTTP client. | ||
|
||
This client implements the `Sentry.HTTPClient` behaviour. | ||
|
||
It's based on the [Finch](https://github.com/sneako/finch) Elixir HTTP client, | ||
which is an *optional dependency* of this library. If you wish to use another | ||
HTTP client, you'll have to implement your own `Sentry.HTTPClient`. See the | ||
documentation for `Sentry.HTTPClient` for more information. | ||
|
||
Finch is built on top of [NimblePool](https://github.com/dashbitco/nimble_pool). If you need to set other pool configuration options, | ||
see "Pool Configuration Options" in the Finch documentation for details on the possible map values. | ||
[finch configuration options](https://hexdocs.pm/finch/Finch.html#start_link/1-pool-configuration-options) | ||
""" | ||
@impl true | ||
def child_spec do | ||
if Code.ensure_loaded?(Finch) do | ||
case Application.ensure_all_started(:finch) do | ||
{:ok, _apps} -> :ok | ||
{:error, reason} -> raise "failed to start the :finch application: #{inspect(reason)}" | ||
end | ||
|
||
Finch.child_spec( | ||
name: __MODULE__, | ||
pools: %{ | ||
:default => [ | ||
size: Sentry.Config.max_finch_connections(), | ||
conn_max_idle_time: Sentry.Config.finch_timeout() | ||
] | ||
} | ||
) | ||
else | ||
raise """ | ||
cannot start the :sentry application because the HTTP client is set to \ | ||
Sentry.FinchClient (which is the default), but the :finch library is not loaded. \ | ||
Add :finch to your dependencies to fix this. | ||
""" | ||
end | ||
end | ||
|
||
@impl true | ||
def post(url, headers, body) do | ||
request = Finch.build(:post, url, headers, body) | ||
|
||
case Finch.request(request, __MODULE__) do | ||
{:ok, %Finch.Response{status: status, headers: headers, body: body}} -> | ||
{:ok, status, headers, body} | ||
|
||
{:error, error} -> | ||
{:error, error} | ||
end | ||
end | ||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to
t:Finch.request_opt()
, this should be:receive_timeout