Skip to content

Commit

Permalink
fix: Backport Rack proxy event to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fbogsany committed Dec 15, 2023
1 parent 1fa0810 commit 3c49d7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def call(env)
tracer.in_span(request_span_name,
attributes: request_span_attributes(env: env),
kind: request_span_kind) do |request_span|
request_start_time = OpenTelemetry::Instrumentation::Rack::Util::QueueTime.get_request_start(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
let(:exporter) { EXPORTER }
let(:finished_spans) { exporter.finished_spans }
let(:first_span) { exporter.finished_spans.first }
let(:proxy_event) { first_span.events&.first }

let(:default_config) { {} }
let(:config) { default_config }
Expand Down Expand Up @@ -84,6 +85,15 @@
end
end

describe 'given request proxy headers' do
let(:env) { Hash('HTTP_X_REQUEST_START' => '1677723466') }

it 'records an event' do
_(proxy_event.name).must_equal 'http.proxy.request.started'
_(proxy_event.timestamp).must_equal 1_677_723_466_000_000_000
end
end

describe 'config[:untraced_endpoints]' do
describe 'when an array is passed in' do
let(:config) { { untraced_endpoints: ['/ping'] } }
Expand Down

0 comments on commit 3c49d7e

Please sign in to comment.