Skip to content

Commit

Permalink
Allow config.transport.proxy to be a String or URI (#1788)
Browse files Browse the repository at this point in the history
Fixes #1782

Update `config.transport.proxy` to allow String and URI values as
previously supported by `sentry-ruby` versions <= 4.8 using Faraday.
  • Loading branch information
jknipp committed Apr 8, 2022
1 parent a1ea253 commit 039a4fc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- [Discussion thread and explanation on the decision](https://github.com/rails/rails/pull/43625#issuecomment-1072514175)
- Check if ActiveRecord connection exists before calling AR connection pool [#1769](https://github.com/getsentry/sentry-ruby/pull/1769)
- Fixes [#1745](https://github.com/getsentry/sentry-ruby/issues/1745)
- Update `config.transport.proxy` to allow String and URI values as previously supported by `sentry-ruby` versions <= 4.8 using Faraday
- Fixes [#1782](https://github.com/getsentry/sentry-ruby/issues/1782)

### Refactoring

Expand Down Expand Up @@ -79,8 +81,8 @@

<img width="80%" src="https://user-images.githubusercontent.com/6536764/157057827-2893527e-7973-4901-a070-bd78a720574a.png">

The SDK now supports [automatic session tracking / release health](https://docs.sentry.io/product/releases/health/) by default in Rack based applications.
Aggregate statistics on successful / errored requests are collected and sent to the server every minute.
The SDK now supports [automatic session tracking / release health](https://docs.sentry.io/product/releases/health/) by default in Rack based applications.
Aggregate statistics on successful / errored requests are collected and sent to the server every minute.
To use this feature, make sure the SDK can detect your app's release. Or you have set it with:

```ruby
Expand Down
16 changes: 15 additions & 1 deletion sentry-ruby/lib/sentry/transport/http_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def conn
server = URI(@dsn.server)

connection =
if proxy = @transport_configuration.proxy
if proxy = normalize_proxy(@transport_configuration.proxy)
::Net::HTTP.new(server.hostname, server.port, proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
else
::Net::HTTP.new(server.hostname, server.port, nil)
Expand All @@ -148,6 +148,20 @@ def conn
connection
end

def normalize_proxy(proxy)
return proxy unless proxy

case proxy
when String
uri = URI(proxy)
{ uri: uri, user: uri.user, password: uri.password }
when URI
{ uri: proxy, user: proxy.user, password: proxy.password }
when Hash
proxy
end
end

def ssl_configuration
configuration = {
verify: @transport_configuration.ssl_verification,
Expand Down
26 changes: 26 additions & 0 deletions sentry-ruby/spec/sentry/transport/http_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@
subject.send_data(data)
end

it "accepts a custom proxy string" do
configuration.transport.proxy = "https://stan:foobar@example.com:8080"

stub_request(fake_response) do |_, http_obj|
expect(http_obj.proxy_address).to eq("example.com")
expect(http_obj.proxy_user).to eq("stan")
expect(http_obj.proxy_pass).to eq("foobar")
expect(http_obj.proxy_port).to eq(8080)
end

subject.send_data(data)
end

it "accepts a custom proxy URI" do
configuration.transport.proxy = URI("https://stan:foobar@example.com:8080")

stub_request(fake_response) do |_, http_obj|
expect(http_obj.proxy_address).to eq("example.com")
expect(http_obj.proxy_user).to eq("stan")
expect(http_obj.proxy_pass).to eq("foobar")
expect(http_obj.proxy_port).to eq(8080)
end

subject.send_data(data)
end

it "accepts custom timeout" do
configuration.transport.timeout = 10

Expand Down

0 comments on commit 039a4fc

Please sign in to comment.