Skip to content

Commit

Permalink
Add http.url to Excon instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tt committed Jun 16, 2024
1 parent a130f81 commit aa59f0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def request_call(datum)
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_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 @@ -53,6 +53,7 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(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 @@ -76,6 +77,7 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(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 @@ -94,6 +96,7 @@
_(span.attributes['http.method']).must_equal 'GET'
_(span.attributes['http.scheme']).must_equal 'http'
_(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 Down Expand Up @@ -124,6 +127,7 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(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 @@ -235,7 +239,7 @@
_(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 @@ -251,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 @@ -299,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.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

0 comments on commit aa59f0c

Please sign in to comment.