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

Set host or address as resource for Net::HTTP #278

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 11 additions & 10 deletions lib/ddtrace/contrib/http/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,18 @@ def request(req, body = nil, &block) # :yield: +response+

pin.tracer.trace(NAME) do |span|
begin
if req.respond_to?(:uri) && req.uri
host_address = req.uri.host
host_port = req.uri.port.to_s
else
host_address = @address
host_port = @port.to_s
end

span.service = pin.service
span.span_type = Datadog::Ext::HTTP::TYPE

span.resource = req.method
# Using the method as a resource, as URL/path can trigger
# a possibly infinite number of resources.
span.resource = "#{host_address}:#{host_port}"
span.set_tag(Datadog::Ext::HTTP::URL, req.path)
span.set_tag(Datadog::Ext::HTTP::METHOD, req.method)

Expand All @@ -133,13 +139,8 @@ def request(req, body = nil, &block) # :yield: +response+
response = request_without_datadog(req, body, &block)
end
span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code)
if req.respond_to?(:uri) && req.uri
span.set_tag(Datadog::Ext::NET::TARGET_HOST, req.uri.host)
span.set_tag(Datadog::Ext::NET::TARGET_PORT, req.uri.port.to_s)
else
span.set_tag(Datadog::Ext::NET::TARGET_HOST, @address)
span.set_tag(Datadog::Ext::NET::TARGET_PORT, @port.to_s)
end
span.set_tag(Datadog::Ext::NET::TARGET_HOST, host_address)
span.set_tag(Datadog::Ext::NET::TARGET_PORT, host_port)

case response.code.to_i / 100
when 4
Expand Down
2 changes: 1 addition & 1 deletion test/contrib/http/miniapp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def check_span_page(span)
def check_span_get(span, parent_id, trace_id)
assert_equal('http.request', span.name)
assert_equal('net/http', span.service)
assert_equal('GET', span.resource)
assert_equal("#{ELASTICSEARCH_HOST}:#{ELASTICSEARCH_PORT}", span.resource)
assert_equal('_cluster/health', span.get_tag('http.url'))
assert_equal('GET', span.get_tag('http.method'))
assert_equal('200', span.get_tag('http.status_code'))
Expand Down
8 changes: 4 additions & 4 deletions test/contrib/http/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_get_request
span = spans[0]
assert_equal('http.request', span.name)
assert_equal('net/http', span.service)
assert_equal('GET', span.resource)
assert_equal("#{ELASTICSEARCH_HOST}:#{ELASTICSEARCH_PORT}", span.resource)
assert_equal('_cluster/health', span.get_tag('http.url'))
assert_equal('GET', span.get_tag('http.method'))
assert_equal('200', span.get_tag('http.status_code'))
Expand All @@ -52,7 +52,7 @@ def test_post_request
span = spans[0]
assert_equal('http.request', span.name)
assert_equal('net/http', span.service)
assert_equal('POST', span.resource)
assert_equal("#{ELASTICSEARCH_HOST}:#{ELASTICSEARCH_PORT}", span.resource)
assert_equal('/my/thing/42', span.get_tag('http.url'))
assert_equal('POST', span.get_tag('http.method'))
assert_equal('127.0.0.1', span.get_tag('out.host'))
Expand All @@ -68,7 +68,7 @@ def test_404
span = spans[0]
assert_equal('http.request', span.name)
assert_equal('net/http', span.service)
assert_equal('GET', span.resource)
assert_equal("#{ELASTICSEARCH_HOST}:#{ELASTICSEARCH_PORT}", span.resource)
assert_equal('/admin.php?user=admin&passwd=123456', span.get_tag('http.url'))
assert_equal('GET', span.get_tag('http.method'))
assert_equal('404', span.get_tag('http.status_code'))
Expand All @@ -93,7 +93,7 @@ def test_pin_block_call
span = spans[0]
assert_equal('http.request', span.name)
assert_equal('net/http', span.service)
assert_equal('GET', span.resource)
assert_equal("#{ELASTICSEARCH_HOST}:#{ELASTICSEARCH_PORT}", span.resource)
assert_equal('/_cluster/health', span.get_tag('http.url'))
assert_equal('GET', span.get_tag('http.method'))
assert_equal('200', span.get_tag('http.status_code'))
Expand Down