Skip to content

Commit

Permalink
Add query string test for net/http integration
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Aug 9, 2023
1 parent 0ec5812 commit 5906da4
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/datadog/tracing/contrib/ethon/easy_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,15 @@
expect(span.get_tag('out.host')).to eq('example.com')
end
end

context 'when query string in url' do
it 'does not collect string' do
easy = EthonSupport.ethon_easy_new(url: 'http://example.com/sample/path?foo=bar')

easy.perform

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
end
end
end
16 changes: 16 additions & 0 deletions spec/datadog/tracing/contrib/excon/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,20 @@
expect(span.get_tag('out.host')).to eq('example.com')
end
end

context 'when query string in url' do
before do
call_web_mock_function_with_agent_host_exclusions { |options| WebMock.enable! options }
stub_request(:get, /example.com/).to_return(status: 200)
end

after { WebMock.disable! }

it 'does not query string' do

This comment has been minimized.

Copy link
@marcotc

marcotc Aug 9, 2023

Member
    it 'does not collect the query string' do
Excon.get('http://example.com/sample/path?foo=bar')

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')

This comment has been minimized.

Copy link
@marcotc

marcotc Aug 9, 2023

Member

I don't think the hostname is relevant for these tests.

end
end
end
14 changes: 14 additions & 0 deletions spec/datadog/tracing/contrib/faraday/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@
expect { response }.to_not output(/WARNING/).to_stderr
end
end

context 'with query sting in url' do
subject(:response) { client.get('http://example.com/success?foo=bar') }

it 'does not collect query string' do
expect(response.status).to eq(200)

expect(span.get_tag('http.url')).to eq('/success')
end

it 'executes without warnings' do
expect { response }.to_not output(/WARNING/).to_stderr
end
end
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/datadog/tracing/contrib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,33 @@ def expect_request_without_distributed_headers
expect(span.get_tag('out.host')).to eq('example.com')
end
end

context 'when query string in url' do
before do
call_web_mock_function_with_agent_host_exclusions { |options| WebMock.enable! options }
stub_request(:get, /example.com/).to_return(status: 200)
end

after { WebMock.disable! }

it 'does not collect query string' do
uri = URI('http://example.com/sample/path?foo=bar')

Net::HTTP.get_response(uri)

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
end

it 'does not collect query string' do
uri = URI('http://example.com/sample/path')
params = { :foo => "bar" }
uri.query = URI.encode_www_form(params)

Net::HTTP.get_response(uri)

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
end
end
end
11 changes: 11 additions & 0 deletions spec/datadog/tracing/contrib/httpclient/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,16 @@
expect(span.get_tag('out.host')).to eq('localhost')
end
end

context 'when query string in url' do
let(:path) { '/sample/path?foo=bar' }

it 'does not collect query string' do
response

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('localhost')
end
end
end
end
11 changes: 11 additions & 0 deletions spec/datadog/tracing/contrib/httprb/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,16 @@
expect(span.get_tag('out.host')).to eq('localhost')
end
end

context 'when query string in url' do
let(:path) { '/sample/path?foo=bar' }

it 'does not collect auth info' do
response

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('localhost')
end
end
end
end
15 changes: 15 additions & 0 deletions spec/datadog/tracing/contrib/rest_client/request_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@
end
end

context 'when query string in url' do
let(:path) { '/sample/path?foo=bar' }

before do
stub_request(:get, /example.com/).to_return(status: status, body: response)
end

it 'does not collect query string' do
request

expect(span.get_tag('http.url')).to eq('/sample/path')
expect(span.get_tag('out.host')).to eq('example.com')
end
end

context 'that returns a custom response object' do
subject(:request) do
RestClient::Request.execute(method: :get, url: url) { response }
Expand Down

0 comments on commit 5906da4

Please sign in to comment.