Skip to content

Commit 2a9dc08

Browse files
fix: Raise original Ethon error after span updates (#1740)
Previously, we recorded the error status and finished the span without re-raising the original error. This was a mistake. Resolves #1739 Co-authored-by: Ariel Valentin <[email protected]>
1 parent 8e3c6c6 commit 2a9dc08

File tree

6 files changed

+68
-48
lines changed

6 files changed

+68
-48
lines changed

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ def perform
3939
otel_before_request
4040
super
4141
rescue StandardError => e
42-
# If an exception occurs before we can call `complete`, we should add and error status and close the span
42+
# If an exception occurs before we can call `complete`
43+
# we should add an error status and close the span
44+
# and raise the original error
4345
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
4446
@otel_span&.finish
4547
@otel_span = nil
48+
raise e
4649
end
4750

4851
def complete

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ def perform
3636
otel_before_request
3737
super
3838
rescue StandardError => e
39-
# If an exception occurs before we can call `complete`, we should add and error status and close the span
39+
# If an exception occurs before we can call `complete`
40+
# we should add an error status and close the span
41+
# and raise the original error
4042
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
4143
@otel_span&.finish
4244
@otel_span = nil
45+
raise e
4346
end
4447

4548
def complete

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ def perform
3939
otel_before_request
4040
super
4141
rescue StandardError => e
42-
# If an exception occurs before we can call `complete`, we should add and error status and close the span
42+
# If an exception occurs before we can call `complete`
43+
# we should add an error status and close the span
44+
# and raise the original error
4345
@otel_span&.status = OpenTelemetry::Trace::Status.error("Request threw an exception: #{e.message}")
4446
@otel_span&.finish
4547
@otel_span = nil
48+
raise e
4649
end
4750

4851
def complete

instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,26 @@
8383
end
8484
end
8585

86-
it 'when the perform fails before complete with an exception' do
87-
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
88-
easy.perform
89-
90-
# NOTE: check the finished spans since we expect to have closed it
91-
span = exporter.finished_spans.first
92-
_(span.name).must_equal 'HTTP'
93-
_(span.attributes['http.method']).must_equal 'N/A'
94-
_(span.attributes['http.status_code']).must_be_nil
95-
_(span.attributes['http.url']).must_equal 'http://example.com/test'
96-
_(span.attributes['http.request.method']).must_equal '_OTHER'
97-
_(span.attributes['http.response.status_code']).must_be_nil
98-
_(span.attributes['url.full']).must_equal 'http://example.com/test'
99-
_(span.status.code).must_equal(
100-
OpenTelemetry::Trace::Status::ERROR
101-
)
102-
_(easy.instance_eval { @otel_span }).must_be_nil
86+
describe 'when the perform fails before complete with an exception' do
87+
it 'raises the original error and closes the span with error status' do
88+
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
89+
assert_raises StandardError, 'Connection failed' do
90+
easy.perform
91+
end
92+
# NOTE: check the finished spans since we expect to have closed it
93+
span = exporter.finished_spans.first
94+
_(span.name).must_equal 'HTTP'
95+
_(span.attributes['http.method']).must_equal 'N/A'
96+
_(span.attributes['http.status_code']).must_be_nil
97+
_(span.attributes['http.url']).must_equal 'http://example.com/test'
98+
_(span.attributes['http.request.method']).must_equal '_OTHER'
99+
_(span.attributes['http.response.status_code']).must_be_nil
100+
_(span.attributes['url.full']).must_equal 'http://example.com/test'
101+
_(span.status.code).must_equal(
102+
OpenTelemetry::Trace::Status::ERROR
103+
)
104+
_(easy.instance_eval { @otel_span }).must_be_nil
105+
end
103106
end
104107
end
105108
end

instrumentation/ethon/test/opentelemetry/instrumentation/ethon/old/instrumentation_test.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,24 @@
7878
end
7979
end
8080

81-
it 'when the perform fails before complete with an exception' do
82-
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
83-
easy.perform
84-
85-
# NOTE: check the finished spans since we expect to have closed it
86-
span = exporter.finished_spans.first
87-
_(span.name).must_equal 'HTTP N/A'
88-
_(span.attributes['http.method']).must_equal 'N/A'
89-
_(span.attributes['http.status_code']).must_be_nil
90-
_(span.attributes['http.url']).must_equal 'http://example.com/test'
91-
_(span.status.code).must_equal(
92-
OpenTelemetry::Trace::Status::ERROR
93-
)
94-
_(easy.instance_eval { @otel_span }).must_be_nil
81+
describe 'when the perform fails before complete with an exception' do
82+
it 'raises the original error and closes the span with error status' do
83+
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
84+
assert_raises StandardError, 'Connection failed' do
85+
easy.perform
86+
end
87+
88+
# NOTE: check the finished spans since we expect to have closed it
89+
span = exporter.finished_spans.first
90+
_(span.name).must_equal 'HTTP N/A'
91+
_(span.attributes['http.method']).must_equal 'N/A'
92+
_(span.attributes['http.status_code']).must_be_nil
93+
_(span.attributes['http.url']).must_equal 'http://example.com/test'
94+
_(span.status.code).must_equal(
95+
OpenTelemetry::Trace::Status::ERROR
96+
)
97+
_(easy.instance_eval { @otel_span }).must_be_nil
98+
end
9599
end
96100
end
97101
end

instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,24 @@
7979
end
8080
end
8181

82-
it 'when the perform fails before complete with an exception' do
83-
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
84-
easy.perform
85-
86-
# NOTE: check the finished spans since we expect to have closed it
87-
span = exporter.finished_spans.first
88-
_(span.name).must_equal 'HTTP'
89-
_(span.attributes['http.request.method']).must_equal '_OTHER'
90-
_(span.attributes['http.response.status_code']).must_be_nil
91-
_(span.attributes['url.full']).must_equal 'http://example.com/test'
92-
_(span.status.code).must_equal(
93-
OpenTelemetry::Trace::Status::ERROR
94-
)
95-
_(easy.instance_eval { @otel_span }).must_be_nil
82+
describe 'when the perform fails before complete with an exception' do
83+
it 'raises the original error and closes the span with error status' do
84+
Ethon::Curl.stub(:easy_perform, ->(_handle) { raise StandardError, 'Connection failed' }) do
85+
assert_raises StandardError, 'Connection failed' do
86+
easy.perform
87+
end
88+
89+
# NOTE: check the finished spans since we expect to have closed it
90+
span = exporter.finished_spans.first
91+
_(span.name).must_equal 'HTTP'
92+
_(span.attributes['http.request.method']).must_equal '_OTHER'
93+
_(span.attributes['http.response.status_code']).must_be_nil
94+
_(span.attributes['url.full']).must_equal 'http://example.com/test'
95+
_(span.status.code).must_equal(
96+
OpenTelemetry::Trace::Status::ERROR
97+
)
98+
_(easy.instance_eval { @otel_span }).must_be_nil
99+
end
96100
end
97101
end
98102
end

0 commit comments

Comments
 (0)