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

fix: Add http.url to Excon instrumentation #1020

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def request_call(datum)
http_method = HTTP_METHODS_TO_UPPERCASE[datum[:method]]

attributes = {
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],
OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => http_method,
OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => datum[:scheme],
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => datum[:path],
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],
OpenTelemetry::SemanticConventions::Trace::HTTP_URL => OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum)),
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => datum[:hostname],
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => datum[:port]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@

_(exporter.finished_spans.size).must_equal 1
_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['http.url']).must_equal 'http://example.com/success'
assert_requested(
:get,
'http://example.com/success',
Expand All @@ -71,11 +72,12 @@

_(exporter.finished_spans.size).must_equal 1
_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.target']).must_equal '/failure'
_(span.attributes['http.url']).must_equal 'http://example.com/failure'
assert_requested(
:get,
'http://example.com/failure',
Expand All @@ -90,10 +92,11 @@

_(exporter.finished_spans.size).must_equal 1
_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.target']).must_equal '/timeout'
_(span.attributes['http.url']).must_equal 'http://example.com/timeout'
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
Expand All @@ -119,11 +122,12 @@

_(exporter.finished_spans.size).must_equal 1
_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.method']).must_equal 'OVERRIDE'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['http.url']).must_equal 'http://example.com/success'
_(span.attributes['test.attribute']).must_equal 'test.value'
assert_requested(
:get,
Expand Down Expand Up @@ -186,8 +190,8 @@

_(exporter.finished_spans.size).must_equal 1
_(span.name).must_equal 'HTTP GET'
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.host']).must_equal 'example.com'
_(span.attributes['http.method']).must_equal 'GET'
end

it 'creates a span on connect for a non-ignored request' do
Expand Down Expand Up @@ -215,6 +219,8 @@
end

it 'emits span on connect' do
port = nil

TCPServer.open('localhost', 0) do |server|
Thread.start do
server.accept
Expand All @@ -231,8 +237,9 @@
_(span.name).must_equal 'connect'
_(span.attributes['net.peer.name']).must_equal('localhost')
_(span.attributes['net.peer.port']).wont_be_nil
_(span.attributes['net.peer.port']).must_equal(port)

assert_http_spans(target: '/example', exception: 'Excon::Error::Timeout')
assert_http_spans(port: port, target: '/example', exception: 'Excon::Error::Timeout')
end

it 'captures errors' do
Expand All @@ -248,7 +255,7 @@
# Depending on the Ruby and Excon Version this will be a SocketError, Socket::ResolutionError or Resolv::ResolvError
_(span_event.attributes['exception.type']).must_match(/(Socket|Resolv)/)

assert_http_spans(host: 'invalid.com', target: '/example')
assert_http_spans(host: 'invalid.com', port: 99_999, target: '/example')
end

it '[BUG] fails to emit an HTTP CONNECT span when connecting through an SSL proxy for an HTTP service' do
Expand Down Expand Up @@ -296,13 +303,14 @@
end
end

def assert_http_spans(scheme: 'http', host: 'localhost', target: '/', exception: nil)
def assert_http_spans(scheme: 'http', host: 'localhost', port: nil, target: '/', exception: nil)
exporter.finished_spans[1..].each do |http_span|
_(http_span.name).must_equal 'HTTP GET'
_(http_span.attributes['http.host']).must_equal host
_(http_span.attributes['http.method']).must_equal 'GET'
_(http_span.attributes['http.scheme']).must_equal scheme
_(http_span.attributes['http.host']).must_equal host
_(http_span.attributes['http.target']).must_equal target
_(http_span.attributes['http.url']).must_equal "#{scheme}://#{host}#{port&.to_s&.prepend(':')}#{target}"
_(http_span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
Expand Down