Skip to content
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 @@ -38,6 +38,11 @@ def headers=(headers)
def perform
otel_before_request
super
rescue StandardError => e
# If an exception occurs before we can call `complete`, we should add and error status and close the span
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
@otel_span&.finish
@otel_span = nil
end

def complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def headers=(headers)
def perform
otel_before_request
super
rescue StandardError => e
# If an exception occurs before we can call `complete`, we should add and error status and close the span
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
@otel_span&.finish
@otel_span = nil
end

def complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def headers=(headers)
def perform
otel_before_request
super
rescue StandardError => e
# If an exception occurs before we can call `complete`, we should add and error status and close the span
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
@otel_span&.finish
@otel_span = nil
end

def complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@
end
end
end

it 'when the perform fails before complete with an exception' do
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
easy.perform

# NOTE: check the finished spans since we expect to have closed it
span = exporter.finished_spans.first
_(span.name).must_equal 'HTTP'
_(span.attributes['http.method']).must_equal 'N/A'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.url']).must_equal 'http://example.com/test'
_(span.attributes['http.request.method']).must_equal '_OTHER'
_(span.attributes['http.response.status_code']).must_be_nil
_(span.attributes['url.full']).must_equal 'http://example.com/test'
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
_(easy.instance_eval { @otel_span }).must_be_nil
end
end
end

describe '#complete' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@
end
end
end

it 'when the perform fails before complete with an exception' do
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
easy.perform

# NOTE: check the finished spans since we expect to have closed it
span = exporter.finished_spans.first
_(span.name).must_equal 'HTTP N/A'
_(span.attributes['http.method']).must_equal 'N/A'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.url']).must_equal 'http://example.com/test'
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
_(easy.instance_eval { @otel_span }).must_be_nil
end
end
end

describe '#complete' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@
end
end
end

it 'when the perform fails before complete with an exception' do
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
easy.perform

# NOTE: check the finished spans since we expect to have closed it
span = exporter.finished_spans.first
_(span.name).must_equal 'HTTP'
_(span.attributes['http.request.method']).must_equal '_OTHER'
_(span.attributes['http.response.status_code']).must_be_nil
_(span.attributes['url.full']).must_equal 'http://example.com/test'
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
_(easy.instance_eval { @otel_span }).must_be_nil
end
end
end

describe '#complete' do
Expand Down