Skip to content

Commit

Permalink
fix: Unable to use sentry when URI contains non-ascii symbols on Net:…
Browse files Browse the repository at this point in the history
…:HTTP traces. (#2417)

Signed-off-by: Raul Ascencio <raul@kraftanmelding.no>
Co-authored-by: Neel Shah <neelshah.sa@gmail.com>
  • Loading branch information
rascencio-kraft and sl0thentr0py authored Sep 27, 2024
1 parent 399c97d commit 152eb5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- Fix error events missing a DSC when there's an active span ([#2408](https://github.com/getsentry/sentry-ruby/pull/2408))
- Verifies presence of client before adding a breadcrumb ([#2394](https://github.com/getsentry/sentry-ruby/pull/2394))
- Fix `Net:HTTP` integration for non-ASCII URI's ([#2417](https://github.com/getsentry/sentry-ruby/pull/2417))

## 5.19.0

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("#{use_ssl? ? 'https' : 'http'}://#{hostname}#{req.path}")
uri = req.uri || URI.parse(URI::DEFAULT_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 }
Expand Down
16 changes: 16 additions & 0 deletions sentry-ruby/spec/sentry/net/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@
end
end

it "supports non-ascii characters in the path" do
stub_normal_response

uri = URI('http://example.com')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new('/path?q=øgreyfoss&å=vær')

transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)


response = http.request(request)

expect(response.code).to eq("200")
end

it "adds sentry-trace header to the request header" do
uri = URI("http://example.com/path")
http = Net::HTTP.new(uri.host, uri.port)
Expand Down

0 comments on commit 152eb5e

Please sign in to comment.