Skip to content

Sentry ignore proxy system configuration #2131

@miquelbar

Description

@miquelbar

Issue Description

Sentry Ruby does not appear to utilize the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables when a system configures to use a proxy. This issue is causing Sentry to be unable to communicate with Sentry.io

Reproduction Steps

Our system has been set up with the following environment variables to enable proxy usage:

HTTPS_PROXY=http://proxy.internal:3128
no_proxy=localhost
NO_PROXY=localhost
https_proxy=http://proxy.internal:3128
http_proxy=http://proxy.internal:3128
HTTP_PROXY=http://proxy.internal:3128

When I attempted to validate the Sentry execution, I used the following code:

require 'sentry-ruby'

Sentry.init do |config|
  config.dsn = 'https://xxxx@yyyy.ingest.sentry.io/zzzz'

  config.breadcrumbs_logger = [:sentry_logger, :http_logger]
  config.debug = true

  # Sync events
  config.background_worker_threads = 0

  # To activate performance monitoring, set one of these options.
  # We recommend adjusting the value in production:
  config.traces_sample_rate = 1.0
  # or
  config.traces_sampler = lambda do |context|
    0.5
  end
end

Sentry.capture_message("test message")

I encountered the following error:

Event capturing failed: Failed to open TCP connection to yyyy.ingest.sentry.io:443 (execution expired)

Nevertheless, when I execute:

uri = URI('https://xxxx@yyyy.ingest.sentry.io/zzzz')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.get(uri.request_uri)

I'm able to connect to Sentry:

=> #<Net::HTTPNotFound 404 Not Found readbody=true>

So, to be able to connect Sentry I explicitly need to define config.transport.proxy on the initializer:

require 'sentry-ruby'

Sentry.init do |config|
  config.dsn = 'https://xxxx@yyyy.ingest.sentry.io/zzzz'

  config.breadcrumbs_logger = [:sentry_logger, :http_logger]
  config.debug = true
  config.transport.proxy = "http://proxy.internal:3128"

  # Sync events
  config.background_worker_threads = 0

  # To activate performance monitoring, set one of these options.
  # We recommend adjusting the value in production:
  config.traces_sample_rate = 1.0
  # or
  config.traces_sampler = lambda do |context|
    0.5
  end
end

Sentry.capture_message("test message")

Expected Behavior

When the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables are defined, Sentry Ruby should use these settings to route its network requests through the configured proxy, without having to specify the proxy configuration using config.transport.proxy

Actual Behavior

Currently, Sentry Ruby appears to ignore the HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables, which results in Sentry's inability to communicate with Sentry.io due to proxy-related issues.

Ruby Version

3.2.0

SDK Version

5.11.0

Integration and Its Version

No response

Sentry Config

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels
No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions