Skip to content

Commit 74f912c

Browse files
committed
Handle Rack hijacking interface
1 parent c2ffafc commit 74f912c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/event_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def on_finish(request, response)
109109
span = OpenTelemetry::Instrumentation::Rack.current_span
110110
return unless span.recording?
111111

112-
add_response_attributes(span, response) if response
112+
add_response_attributes(span, response) if response && !request.env.key?('rack.hijack?')
113113
rescue StandardError => e
114114
OpenTelemetry.handle_error(exception: e)
115115
ensure

instrumentation/rack/lib/opentelemetry/instrumentation/rack/middlewares/tracer_middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def call(env)
8181
request_span.add_event('http.proxy.request.started', timestamp: request_start_time) unless request_start_time.nil?
8282
OpenTelemetry::Instrumentation::Rack.with_span(request_span) do
8383
@app.call(env).tap do |status, headers, response|
84-
set_attributes_after_request(request_span, status, headers, response)
84+
set_attributes_after_request(request_span, status, headers, response) unless env.key?('rack.hijack?')
8585
config[:response_propagators].each { |propagator| propagator.inject(headers) }
8686
end
8787
end

instrumentation/rack/test/opentelemetry/instrumentation/rack/middlewares/event_handler_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@
105105
_(proxy_event).must_be_nil
106106
end
107107

108+
describe 'with an hijacked response' do
109+
let(:service) do
110+
lambda do |env|
111+
env['rack.hijack?'] = true
112+
[-1, {}, []]
113+
end
114+
end
115+
116+
it 'track a span without error' do
117+
_(rack_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
118+
end
119+
end
120+
108121
describe 'when baggage is set' do
109122
let(:headers) do
110123
Hash(

instrumentation/rack/test/opentelemetry/instrumentation/rack/middlewares/tracer_middleware_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@
7272
_(first_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
7373
end
7474

75+
describe 'with an hijacked response' do
76+
let(:app) do
77+
lambda do |env|
78+
env['rack.hijack?'] = true
79+
[-1, {}, []]
80+
end
81+
end
82+
83+
it 'track a span without error' do
84+
_(first_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
85+
end
86+
end
87+
7588
it 'has no parent' do
7689
_(first_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
7790
end

0 commit comments

Comments
 (0)