Issue Description
Hi - when I added Sentry to a rails app I started getting weird exceptions like this when using XMLRPC (NOTE: IPv6 works with basic Net::HTTP requests
irb(main):004:0>XMLRPC::Client.new('::1', '/RPC2', 8080).call('system.listMethods')
/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://::1/RPC2" (URI::InvalidURIError)
I've found with the backtrace it's caused by sentry hijacking any Net::HTTP requests for its own logging
/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://::1/RPC2" (URI::InvalidURIError)
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:67:in `split'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:72:in `parse'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/common.rb:188:in `parse'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:80:in `extract_request_info'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:33:in `block in request'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/hub.rb:102:in `with_child_span'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry-ruby.rb:456:in `with_child_span'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:32:in `request'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/net/http.rb:1484:in `request_post'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:498:in `do_rpc'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:287:in `call2'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:268:in `call'",
I thought it was an issue with xmlrpc but it's not ruby/xmlrpc#42
IPv6 literal notation uses square brackets to allow parsing of a port number:
[::1]:8080
sentry/net/http.rb:80 extract_request_info
uri = req.uri || URI.parse("#{use_ssl? ? 'https' : 'http'}://#{address}#{req.path}")
This line tries to rebuild the URI from the attributes of the Net::HTTP instance, which fails because address is ::1. Not a valid hostname. I think you probably need to add a regex using the resolv gem or a manual check to see if the address contains colons meaning it's an IPv6 address.
The reason this works with basic Net::HTTP requests is when those are made they have their uri attribute set correctly. When making an XMLRPC::Client request, the uri isn't set so the fallback URI.parse is called which then fails
Reproduction Steps
add sentry-ruby to your gemfile
require 'xmlrpc/client'
XMLRPC::Client.new('::1', '/RPC2', 8080).call('system.listMethods')
Expected Behavior
XMLRPC call should work
Actual Behavior
/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "http://::1/RPC2" (URI::InvalidURIError)
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:67:in `split'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/rfc3986_parser.rb:72:in `parse'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/uri/common.rb:188:in `parse'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:80:in `extract_request_info'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:33:in `block in request'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/hub.rb:102:in `with_child_span'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry-ruby.rb:456:in `with_child_span'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/sentry-ruby-5.11.0/lib/sentry/net/http.rb:32:in `request'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/3.1.0/net/http.rb:1484:in `request_post'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:498:in `do_rpc'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:287:in `call2'",
"/home/rowan/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/xmlrpc-0.3.3/lib/xmlrpc/client.rb:268:in `call'",
Ruby Version
3.1.0
SDK Version
5.11
Integration and Its Version
Rails + Sidekiq
Sentry Config
Sentry.init do |config|
config.enabled_environments = %w[production]
config.dsn = Rails.configuration.sentry[:dsn]
if Sidekiq.server?
# We're in sidekiq
# Don't use HTTP logger yet there's a bug that will kill CycleMatcher
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
else
# We're in the web app
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
end
To activate performance monitoring, set one of these options.
We recommend adjusting the value in production:
config.traces_sample_rate = 0.1
end
Issue Description
Hi - when I added Sentry to a rails app I started getting weird exceptions like this when using XMLRPC (NOTE: IPv6 works with basic Net::HTTP requests
I've found with the backtrace it's caused by sentry hijacking any Net::HTTP requests for its own logging
I thought it was an issue with
xmlrpcbut it's not ruby/xmlrpc#42IPv6 literal notation uses square brackets to allow parsing of a port number:
[::1]:8080This line tries to rebuild the URI from the attributes of the Net::HTTP instance, which fails because
addressis::1. Not a valid hostname. I think you probably need to add a regex using theresolvgem or a manual check to see if the address contains colons meaning it's an IPv6 address.The reason this works with basic Net::HTTP requests is when those are made they have their
uriattribute set correctly. When making anXMLRPC::Clientrequest, the uri isn't set so the fallbackURI.parseis called which then failsReproduction Steps
add sentry-ruby to your gemfile
Expected Behavior
XMLRPC call should work
Actual Behavior
Ruby Version
3.1.0
SDK Version
5.11
Integration and Its Version
Rails + Sidekiq
Sentry Config
Sentry.init do |config|
config.enabled_environments = %w[production]
config.dsn = Rails.configuration.sentry[:dsn]
if Sidekiq.server?
# We're in sidekiq
# Don't use HTTP logger yet there's a bug that will kill CycleMatcher
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
else
# We're in the web app
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
end
To activate performance monitoring, set one of these options.
We recommend adjusting the value in production:
config.traces_sample_rate = 0.1
end