Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing: Exclude query string for http.url tag from net/http instrumentation #3045

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/datadog/tracing/contrib/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative '../../metadata/ext'
require_relative '../analytics'
require_relative '../http_annotation_helper'
require_relative '../utils/quantization/http'

module Datadog
module Tracing
Expand Down Expand Up @@ -79,8 +80,10 @@ def annotate_span_with_request!(span, request, request_options)

span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)

span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_URL, request.path)
span.set_tag(
Tracing::Metadata::Ext::HTTP::TAG_URL,
Contrib::Utils::Quantization::HTTP.url(request.path, { query: { exclude: :all } })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine as a default, and you've added tests to make sure there aren't any query strings in other integrations.

Is it worth putting this same quantization line in those integrations as well? For consistency? Or is there a drawback?

Copy link
Contributor Author

@TonyCTHsu TonyCTHsu Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, our http client integrations do not offer settings for quantization, each of them leverage their public interface to provide data.

I believe we should refactor and centralize the quantization mechanism when we offer the feature.

)
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_METHOD, request.method)

host, port = host_and_port(request)
Expand Down
10 changes: 10 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,14 @@
expect(span.get_tag('out.host')).to eq('example.com')
end
end

context 'when query string in url' do
it 'does not collect query 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')
end
end
end
15 changes: 15 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,19 @@
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
Excon.get('http://example.com/sample/path?foo=bar')

expect(span.get_tag('http.url')).to eq('/sample/path')
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
17 changes: 17 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,21 @@ 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')
end
end
end
10 changes: 10 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,15 @@
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')
end
end
end
end
10 changes: 10 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,15 @@
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')
end
end
end
end
14 changes: 14 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,20 @@
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')
end
end

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