Skip to content

Switch HTTP Client from Hackney to Finch #897

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

savhappy
Copy link
Collaborator

Switch default HTTP client from Hackney to Finch

Changes

  • Changes the default HTTP client from Sentry.HackneyClient to Sentry.FinchClient
  • Adds new Finch-specific configuration options:
    • finch_pool_opts: For pool configuration (defaults to [size: 50, conn_max_idle_time: 5000])
    • finch_request_opts: For request configuration (defaults to [receive_timeout: 5000])
  • Deprecates Hackney-specific options
  • Updates tests to use Finch configuration
  • Updates documentation to reflect Finch as the default client

Migration

Users who want to continue using Hackney can:

  1. Explicitly configure Sentry to use Hackney:
config :sentry,
  client: Sentry.HackneyClient

Dependencies

  • Adds Finch as an optional dependency
  • Keeps Hackney as an optional dependency for backward compatibility

Testing

  • Updated all tests to use Finch configuration
  • Added tests for Finch-specific error handling
  • Verified backward compatibility with Hackney

Documentation

Copy link

github-actions bot commented May 27, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Switch HTTP Client from Hackney to Finch ([#897](https://github.com/getsentry/sentry-elixir/pull/897))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 8af8dce

Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely work. Left a few first-pass comments, but they're mostly nits to clean this up for a nice release. Let me know if you have questions and otherwise let me know when this is ready for another review pass 🙃


```elixir
defp deps do
[
# ...

{:sentry, "~> 10.8"},
{:hackney, "~> 1.20"}
{:jason, "~> 1.4"},
{:finch, "~> 0.19"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but let's suggest a version requirement that wouldn't technically allow breaking versions (since this is before 1.0):

Suggested change
{:finch, "~> 0.19"}
{:finch, "~> 0.19.0"}

@@ -67,7 +67,7 @@ defmodule Mix.Tasks.Sentry.SendTestEvent do
end

Mix.shell().info("current environment_name: #{inspect(to_string(Config.environment_name()))}")
Mix.shell().info("hackney_opts: #{inspect(Config.hackney_opts())}\n")
Mix.shell().info("finch_pool_opts: #{inspect(Config.finch_pool_opts())}\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're touching this... a nit! 😉

Suggested change
Mix.shell().info("finch_pool_opts: #{inspect(Config.finch_pool_opts())}\n")
Mix.shell().info("Finch pool options: #{inspect(Config.finch_pool_opts(), pretty: true)}\n")

applied if `:client` is set to `Sentry.HackneyClient`.
"""
] ++
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch instead as default client."]),
if(Mix.env() == :test, do: [], else: [deprecated: "Use Finch as the default HTTP client instead."]),

type: :keyword_list,
default: [pool: :sentry_pool],
default: [size: 50, conn_max_idle_time: 5000],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the 5000 idle time? I think Finch's default of :infinity is a good choice here?

@behaviour Sentry.HTTPClient

@moduledoc """
The built-in HTTP client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shows up correctly in the module doc summary with ExDoc:

Suggested change
The built-in HTTP client.
The built-in HTTP client.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
@impl true
@impl true

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)
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
"""
"""
@moduledoc since: "10.11.0"

@@ -2,7 +2,7 @@ defmodule Sentry.HTTPClient do
@moduledoc """
A behaviour for HTTP clients that Sentry can use.

The default HTTP client is `Sentry.HackneyClient`.
The default HTTP client is `Sentry.FinchClient`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The default HTTP client is `Sentry.FinchClient`.
The default HTTP client is `Sentry.FinchClient` since v10.11.0
(it was based on Hackney before that).

mix.exs Outdated
@@ -97,6 +97,7 @@ defmodule Sentry.Mixfile do

# Optional dependencies
{:hackney, "~> 1.8", optional: true},
{:finch, "~> 0.19", optional: true},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can even go a couple of versions below this to allow more people to use this in case they're stuck on an older Finch version. Something like ~> 0.17. You can look at Finch's changelog and figure out a good balance there 🙃

@savhappy
Copy link
Collaborator Author

@whatyouhide made all the feedback changes! One thing I forgot to mention is the http_client module is still using Finch as an example to add your own.. Should this be updated to hackney or req? Or good as is?

@whatyouhide
Copy link
Collaborator

@savhappy updated to use Req (in another PR) would be great I think 🙃. We also have:

  1. Failing CI
  2. Can you run mix deps.unlock --unused just to make sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch from Hackney to Finch as the default HTTP client
2 participants