Skip to content

Commit

Permalink
Handle Rack hijacking interface
Browse files Browse the repository at this point in the history
  • Loading branch information
j15e committed Oct 19, 2024
1 parent c2ffafc commit 0f26f45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def on_finish(request, response)
span = OpenTelemetry::Instrumentation::Rack.current_span
return unless span.recording?

add_response_attributes(span, response) if response
add_response_attributes(span, response) if response && !request.env.key?('rack.hijack?')
rescue StandardError => e
OpenTelemetry.handle_error(exception: e)
ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def call(env)
request_span.add_event('http.proxy.request.started', timestamp: request_start_time) unless request_start_time.nil?
OpenTelemetry::Instrumentation::Rack.with_span(request_span) do
@app.call(env).tap do |status, headers, response|
set_attributes_after_request(request_span, status, headers, response)
set_attributes_after_request(request_span, status, headers, response) unless env.key?('rack.hijack?')
config[:response_propagators].each { |propagator| propagator.inject(headers) }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@
_(proxy_event).must_be_nil
end

describe 'with an hijacked response' do
let(:service) do
lambda do |env|
env['rack.hijack?'] = true
[-1, {}, []]
end
end

it 'track a span without error' do
_(rack_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
end
end

describe 'when baggage is set' do
let(:headers) do
Hash(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@
_(first_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
end

describe 'with an hijacked response' do
let(:app) do
lambda do |env|
env['rack.hijack?'] = true
[-1, {}, []]
end
end

it 'track a span without error' do
_(first_span.status.code).must_equal OpenTelemetry::Trace::Status::UNSET
end
end

it 'has no parent' do
_(first_span.parent_span_id).must_equal OpenTelemetry::Trace::INVALID_SPAN_ID
end
Expand Down

0 comments on commit 0f26f45

Please sign in to comment.