diff --git a/lib/aws-xray-sdk/facets/rails/active_record.rb b/lib/aws-xray-sdk/facets/rails/active_record.rb index d5b8732..cc6a23a 100644 --- a/lib/aws-xray-sdk/facets/rails/active_record.rb +++ b/lib/aws-xray-sdk/facets/rails/active_record.rb @@ -27,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 = 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: 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