Skip to content

Commit

Permalink
Conditionally handle for ruby 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnjunaid committed Aug 23, 2024
1 parent 373b1ac commit 8d232b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
7 changes: 4 additions & 3 deletions lib/aws-xray-sdk/facets/rails/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'active_record'
require 'aws-xray-sdk/utils/math_utils'

module XRay
module Rails
Expand Down Expand Up @@ -28,9 +27,11 @@ def record(transaction)
subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
# subsegment is nil in case of context missing
return if subsegment.nil?
subsegment.start_time = (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? convert_time_in_seconds(transaction.time.to_f) : transaction.time.to_f
# Rails 7.1 introduced time measurement in milliseconds instead seconds of causing xray-sdk to report wrong duration for transaction calls.
# This is being handled in rails 7.2 and later. https://github.com/rails/rails/pull/50779
subsegment.start_time = (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.time.to_f/1000 : transaction.time.to_f
subsegment.sql = sql
XRay.recorder.end_subsegment end_time: (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? convert_time_in_seconds(transaction.end.to_f) : transaction.end.to_f
XRay.recorder.end_subsegment end_time: (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.end.to_f/1000 : transaction.end.to_f
end

private
Expand Down
12 changes: 0 additions & 12 deletions lib/aws-xray-sdk/utils/math_utils.rb

This file was deleted.

13 changes: 0 additions & 13 deletions test/aws-xray-sdk/tc_time_conversion.rb

This file was deleted.

0 comments on commit 8d232b1

Please sign in to comment.