From 612c8a1260be1e6e87467bc02641d43cb895b919 Mon Sep 17 00:00:00 2001 From: Emiliyan Greshkov Date: Mon, 13 Jan 2025 14:47:43 +0200 Subject: [PATCH 1/4] Use RFC2396_PARSER explicitly to avoid the warning. --- sentry-ruby/lib/sentry/net/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index 04820f3d5..0704d878a 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -66,7 +66,7 @@ def extract_request_info(req) # IPv6 url could look like '::1/path', and that won't parse without # wrapping it in square brackets. hostname = address =~ Resolv::IPv6::Regex ? "[#{address}]" : address - uri = req.uri || URI.parse(URI::DEFAULT_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) + uri = req.uri || URI.parse(URI::RFC2396_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) url = "#{uri.scheme}://#{uri.host}#{uri.path}" rescue uri.to_s result = { method: req.method, url: url } From db9bab0890f6cae46a6322f70202ac500bf8ff96 Mon Sep 17 00:00:00 2001 From: Emiliyan Greshkov Date: Mon, 20 Jan 2025 09:55:23 +0200 Subject: [PATCH 2/4] Add changelog entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ebd52b7d..8ff61bc00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Default to `internal_error` error type for OpenTelemetry spans [#2473](https://github.com/getsentry/sentry-ruby/pull/2473) - Improve `before_send` and `before_send_transaction`'s return value handling ([#2504](https://github.com/getsentry/sentry-ruby/pull/2504)) - Fix a crash when calling `Sentry.get_main_hub` in a trap context ([#2510](https://github.com/getsentry/sentry-ruby/pull/2510)) +- Use `URI::RFC2396_PARSER.escape` explicitly to remove warning logs to stderr ([#2509](https://github.com/getsentry/sentry-ruby/pull/2509)) ### Internal From bee7642f102961236f751e4785a92fa8abc99dec Mon Sep 17 00:00:00 2001 From: Emiliyan Greshkov Date: Mon, 20 Jan 2025 13:41:39 +0200 Subject: [PATCH 3/4] Fallback to DEFAULT_PARSER if RFC2396_PARSER is not found. --- sentry-ruby/lib/sentry/net/http.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index 0704d878a..aa50f1fb2 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -66,7 +66,7 @@ def extract_request_info(req) # IPv6 url could look like '::1/path', and that won't parse without # wrapping it in square brackets. hostname = address =~ Resolv::IPv6::Regex ? "[#{address}]" : address - uri = req.uri || URI.parse(URI::RFC2396_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) + uri = req.uri || URI.parse(uri_parser.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) url = "#{uri.scheme}://#{uri.host}#{uri.path}" rescue uri.to_s result = { method: req.method, url: url } @@ -78,6 +78,12 @@ def extract_request_info(req) result end + + def uri_parser + URI::RFC2396_PARSER + rescue NameError + URI::DEFAULT_PARSER + end end end end From bf7130d08d25103c140ab9c2b75a1dc66ef46365 Mon Sep 17 00:00:00 2001 From: Emiliyan Greshkov Date: Mon, 20 Jan 2025 14:04:00 +0200 Subject: [PATCH 4/4] Refactor uri_parser method into a constant. --- sentry-ruby/lib/sentry/net/http.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sentry-ruby/lib/sentry/net/http.rb b/sentry-ruby/lib/sentry/net/http.rb index aa50f1fb2..1c7450ae9 100644 --- a/sentry-ruby/lib/sentry/net/http.rb +++ b/sentry-ruby/lib/sentry/net/http.rb @@ -13,6 +13,7 @@ module HTTP OP_NAME = "http.client" SPAN_ORIGIN = "auto.http.net_http" BREADCRUMB_CATEGORY = "net.http" + URI_PARSER = URI.const_defined?("RFC2396_PARSER") ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER # To explain how the entire thing works, we need to know how the original Net::HTTP#request works # Here's part of its definition. As you can see, it usually calls itself inside a #start block @@ -66,7 +67,7 @@ def extract_request_info(req) # IPv6 url could look like '::1/path', and that won't parse without # wrapping it in square brackets. hostname = address =~ Resolv::IPv6::Regex ? "[#{address}]" : address - uri = req.uri || URI.parse(uri_parser.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) + uri = req.uri || URI.parse(URI_PARSER.escape("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")) url = "#{uri.scheme}://#{uri.host}#{uri.path}" rescue uri.to_s result = { method: req.method, url: url } @@ -78,12 +79,6 @@ def extract_request_info(req) result end - - def uri_parser - URI::RFC2396_PARSER - rescue NameError - URI::DEFAULT_PARSER - end end end end