diff --git a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb index 8099eca033..e4f4a9d0fe 100644 --- a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb +++ b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb @@ -39,10 +39,13 @@ 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 + # If an exception occurs before we can call `complete` + # we should add an error status and close the span + # and raise the original error @otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}") @otel_span&.finish @otel_span = nil + raise e end def complete diff --git a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb index 7d72e2ed69..4f057f05d5 100644 --- a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb +++ b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb @@ -36,10 +36,13 @@ 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 + # If an exception occurs before we can call `complete` + # we should add an error status and close the span + # and raise the original error @otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}") @otel_span&.finish @otel_span = nil + raise e end def complete diff --git a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb index 1306183ccb..2d8b934080 100644 --- a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb +++ b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb @@ -39,10 +39,13 @@ 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 + # If an exception occurs before we can call `complete` + # we should add an error status and close the span + # and raise the original error @otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}") @otel_span&.finish @otel_span = nil + raise e end def complete diff --git a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb index 76603741c8..8c27b3300e 100644 --- a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb +++ b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb @@ -83,23 +83,26 @@ 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 + describe 'when the perform fails before complete with an exception' do + it 'raises the original error and closes the span with error status' do + Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do + assert_raises StandardError, 'Connection failed' do + easy.perform + end + # 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 end diff --git a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/old/instrumentation_test.rb b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/old/instrumentation_test.rb index 4c9b5cb360..f8c307a97e 100644 --- a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/old/instrumentation_test.rb +++ b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/old/instrumentation_test.rb @@ -78,20 +78,24 @@ 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 + describe 'when the perform fails before complete with an exception' do + it 'raises the original error and closes the span with error status' do + Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do + assert_raises StandardError, 'Connection failed' do + easy.perform + end + + # 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 end diff --git a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb index 4179072ec2..d9317fd008 100644 --- a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb +++ b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb @@ -79,20 +79,24 @@ 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 + describe 'when the perform fails before complete with an exception' do + it 'raises the original error and closes the span with error status' do + Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do + assert_raises StandardError, 'Connection failed' do + easy.perform + end + + # 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 end