Skip to content

Commit e87b946

Browse files
committed
define finch opts and update logger/send_test_event tests
1 parent 99777f3 commit e87b946

File tree

7 files changed

+57
-35
lines changed

7 files changed

+57
-35
lines changed

config/config.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if config_env() == :test do
66
tags: %{},
77
enable_source_code_context: true,
88
root_source_code_paths: [File.cwd!()],
9-
hackney_opts: [recv_timeout: 50, pool: :sentry_pool],
9+
finch_request_opts: [receive_timeout: 50],
1010
send_result: :sync,
1111
send_max_attempts: 1,
1212
dedup_events: false,
@@ -16,3 +16,6 @@ if config_env() == :test do
1616
end
1717

1818
config :phoenix, :json_library, if(Code.ensure_loaded?(JSON), do: JSON, else: Jason)
19+
20+
config :sentry,
21+
client: Sentry.FinchClient

lib/mix/tasks/sentry.send_test_event.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ defmodule Mix.Tasks.Sentry.SendTestEvent do
6767
end
6868

6969
Mix.shell().info("current environment_name: #{inspect(to_string(Config.environment_name()))}")
70-
Mix.shell().info("hackney_opts: #{inspect(Config.hackney_opts())}\n")
70+
Mix.shell().info("finch_pool_opts: #{inspect(Config.finch_pool_opts())}\n")
7171
end
7272

7373
defp send_event(opts) do

lib/sentry/config.ex

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ defmodule Sentry.Config do
316316
The maximum number of attempts to send an event to Sentry.
317317
"""
318318
],
319-
finch_opts: [
319+
finch_pool_opts: [
320320
type: :keyword_list,
321321
default: [size: 50, conn_max_idle_time: 5000],
322322
doc: """
@@ -326,32 +326,48 @@ defmodule Sentry.Config do
326326
for available options.
327327
"""
328328
],
329-
hackney_opts: [
329+
finch_request_opts: [
330330
type: :keyword_list,
331-
default: [pool: :sentry_pool],
331+
default: [receive_timeout: 50],
332332
doc: """
333-
Options to be passed to `hackney`. Only
334-
applied if `:client` is set to `Sentry.HackneyClient`.
335-
"""
336-
],
337-
hackney_pool_timeout: [
338-
type: :timeout,
339-
default: 5000,
340-
doc: """
341-
The maximum time to wait for a
342-
connection to become available. Only applied if `:client` is set to
343-
`Sentry.HackneyClient`.
333+
Request options to be passed to `Finch.request/4`. These options control
334+
individual request behavior. Only applied if `:client` is set to
335+
`Sentry.FinchClient`. See [Finch documentation](https://hexdocs.pm/finch/Finch.html#request/4)
336+
for available options.
344337
"""
345338
],
346-
hackney_pool_max_connections: [
347-
type: :pos_integer,
348-
default: 50,
349-
doc: """
350-
The maximum number of
351-
connections to keep in the pool. Only applied if `:client` is set to
352-
`Sentry.HackneyClient`.
353-
"""
354-
]
339+
hackney_opts:
340+
[
341+
type: :keyword_list,
342+
default: [pool: :sentry_pool],
343+
doc: """
344+
Options to be passed to `hackney`. Only
345+
applied if `:client` is set to `Sentry.HackneyClient`.
346+
"""
347+
] ++
348+
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]),
349+
hackney_pool_timeout:
350+
[
351+
type: :timeout,
352+
default: 5000,
353+
doc: """
354+
The maximum time to wait for a
355+
connection to become available. Only applied if `:client` is set to
356+
`Sentry.HackneyClient`.
357+
"""
358+
] ++
359+
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]),
360+
hackney_pool_max_connections:
361+
[
362+
type: :pos_integer,
363+
default: 50,
364+
doc: """
365+
The maximum number of
366+
connections to keep in the pool. Only applied if `:client` is set to
367+
`Sentry.HackneyClient`.
368+
"""
369+
] ++
370+
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."])
355371
]
356372

357373
source_code_context_opts_schema = [
@@ -617,8 +633,11 @@ defmodule Sentry.Config do
617633
@spec sample_rate() :: float()
618634
def sample_rate, do: fetch!(:sample_rate)
619635

620-
@spec finch_opts() :: keyword()
621-
def finch_opts, do: fetch!(:finch_opts)
636+
@spec finch_pool_opts() :: keyword()
637+
def finch_pool_opts, do: fetch!(:finch_pool_opts)
638+
639+
@spec finch_request_opts() :: keyword()
640+
def finch_request_opts, do: fetch!(:finch_request_opts)
622641

623642
@spec hackney_opts() :: keyword()
624643
def hackney_opts, do: fetch!(:hackney_opts)

lib/sentry/finch_client.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule Sentry.FinchClient do
2323
Finch.child_spec(
2424
name: __MODULE__,
2525
pools: %{
26-
:default => Sentry.Config.finch_opts()
26+
:default => Sentry.Config.finch_pool_opts()
2727
}
2828
)
2929
else
@@ -39,7 +39,7 @@ defmodule Sentry.FinchClient do
3939
def post(url, headers, body) do
4040
request = Finch.build(:post, url, headers, body)
4141

42-
case Finch.request(request, __MODULE__) do
42+
case Finch.request(request, __MODULE__, Sentry.Config.finch_request_opts()) do
4343
{:ok, %Finch.Response{status: status, headers: headers, body: body}} ->
4444
{:ok, status, headers, body}
4545

test/mix/sentry.send_test_event_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
55
import Sentry.TestHelpers
66

77
test "prints if :dsn is not set" do
8-
put_test_config(dsn: nil, hackney_opts: [], environment_name: "some_env")
8+
put_test_config(dsn: nil, finch_pool_opts: [], environment_name: "some_env")
99

1010
output =
1111
capture_io(fn ->
@@ -15,7 +15,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
1515
assert output =~ """
1616
Client configuration:
1717
current environment_name: "some_env"
18-
hackney_opts: []
18+
finch_pool_opts: []
1919
"""
2020

2121
assert output =~ ~s(Event not sent because the :dsn option is not set)
@@ -35,7 +35,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
3535
put_test_config(
3636
dsn: "http://public:secret@localhost:#{bypass.port}/1",
3737
environment_name: "test",
38-
hackney_opts: []
38+
finch_pool_opts: []
3939
)
4040

4141
output =
@@ -49,7 +49,7 @@ defmodule Mix.Tasks.Sentry.SendTestEventTest do
4949
public_key: public
5050
secret_key: secret
5151
current environment_name: "test"
52-
hackney_opts: []
52+
finch_pool_opts: []
5353
"""
5454

5555
assert output =~ "Sending test event..."

test/sentry/logger_handler_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ defmodule Sentry.LoggerHandlerTest do
685685
put_test_config(
686686
dsn: "http://public:secret@localhost:#{bypass.port}/1",
687687
dedup_events: false,
688-
hackney_opts: [recv_timeout: 500, pool: :sentry_pool]
688+
finch_request_opts: [receive_timeout: 500]
689689
)
690690

691691
Bypass.expect(bypass, fn conn ->

test/sentry_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defmodule SentryTest do
5151
test "errors when taking too long to receive response", %{bypass: bypass} do
5252
Bypass.expect(bypass, fn _conn -> Process.sleep(:infinity) end)
5353

54-
put_test_config(hackney_opts: [recv_timeout: 50])
54+
put_test_config(finch_request_opts: [receive_timeout: 50])
5555

5656
assert {:error,
5757
%Sentry.ClientError{

0 commit comments

Comments
 (0)