Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def extract_queue_time(env)
# Parses X-Request-Start header value to extract a timestamp.
# Supports multiple formats:
# - Nginx: "t=1234567890.123" (seconds with decimal)
# - Render: "t=1234567890123456789" (nanoseconds)
# - Heroku, HAProxy 1.9+: "t=1234567890123456" (microseconds)
# - HAProxy < 1.9: "t=1234567890" (seconds)
# - Generic: "1234567890.123" (raw timestamp)
Expand All @@ -158,9 +159,12 @@ def parse_request_start_header(header_value)
return
end

# normalize: timestamps can be in seconds, milliseconds or microseconds
# any timestamp > 10 trillion = microseconds
if timestamp > 10_000_000_000_000
# normalize: timestamps can be in seconds, milliseconds, microseconds or nanoseconds
# any timestamp > 10 quadrillion = nanoseconds
if timestamp > 10_000_000_000_000_000
timestamp / 1_000_000_000.0
# timestamp > 10 trillion & < 10 quadrillion = microseconds
elsif timestamp > 10_000_000_000_000
timestamp / 1_000_000.0
# timestamp > 10 billion & < 10 trillion = milliseconds
elsif timestamp > 10_000_000_000
Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry/rack/capture_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,18 @@ def will_be_sampled_by_sdk
expect(queue_time).to be_within(10).of(30)
end
end

it "handles Render nanosecond timestamp format" do
Timecop.freeze do
timestamp_ns = ((Time.now.to_f - 0.03) * 1_000_000_000).to_i
env["HTTP_X_REQUEST_START"] = "t=#{timestamp_ns}"

stack.call(env)

queue_time = transaction.contexts.dig(:trace, :data, 'http.server.request.time_in_queue')
expect(queue_time).to be_within(10).of(30)
end
end
end

context "without X-Request-Start header" do
Expand Down
Loading