Describe the bug
When running our application in production (via ECS and Fargate), we're seeing an application error which causes the process to die immediately. Here's an example taken from the logs:
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/railtie.rb:190:in `method_missing'
Feb 05 13:04:52.630 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/railtie.rb:190:in `public_send'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/engine.rb:527:in `call'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/rack/capture_exceptions.rb:14:in `call'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry-ruby.rb:149:in `with_scope'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/hub.rb:52:in `with_scope'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/rack/capture_exceptions.rb:42:in `block in call'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-rails-4.2.0/lib/sentry/rails/capture_exceptions.rb:35:in `finish_span'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/transaction.rb:130:in `finish'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/hub.rb:117:in `capture_event'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/client.rb:26:in `capture_event'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/scope.rb:34:in `apply_to_event'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:86:in `rack_env='
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:171:in `calculate_real_ip_from_rack'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:171:in `new'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `initialize'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `map'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `block in initialize'
Feb 05 13:04:52.629 rails /var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `new'
Feb 05 13:04:52.629 rails /usr/lib/fullstaq-ruby/versions/2.6.5-jemalloc/lib/ruby/2.6.0/ipaddr.rb:565:in `initialize'
Feb 05 13:04:52.629 rails #<IPAddr::AddressFamilyError: address family must be specified>
Feb 05 13:04:52.629 rails 2021-02-05 19:04:52 +0000: Rack app error handling request { GET /health_check }
This issue seems to stem from this line: https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/utils/real_ip.rb#L32
It's worth noting that we have trusted_proxies configured within our Rails app:
proxies = %w(
10.10.0.0/16
20.10.0.0/16
20.20.0.0/16
20.30.0.0/16
20.40.0.0/16
)
config.action_dispatch.trusted_proxies = proxies.map { |proxy| IPAddr.new(proxy) }
I tried to set the trusted_proxies configuration to the above array in the Sentry.init block in the initializer myself but the result was the same.
Environment
- Ruby Version: 2.6.5
- SDK Version: 4.2.0
- Integration Versions (if any):
- Rails 6.0
SentryConfig
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
config.breadcrumbs_logger = [:active_support_logger]
config.rails.report_rescued_exceptions = true
config.send_default_pii = true # send ip, cookie, request body
config.enabled_environments = %w(staging production)
config.traces_sample_rate = 0.5
end
Describe the bug
When running our application in production (via ECS and Fargate), we're seeing an application error which causes the process to die immediately. Here's an example taken from the logs:
This issue seems to stem from this line: https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/utils/real_ip.rb#L32
It's worth noting that we have
trusted_proxiesconfigured within our Rails app:I tried to set the
trusted_proxiesconfiguration to the above array in theSentry.initblock in the initializer myself but the result was the same.Environment
SentryConfig