Skip to content

Commit 16d808f

Browse files
ibnjunaidwangzlei
andauthored
Fix issue: Wrong duration for DB transaction event on ROR 7.1 #92 (#96)
* Fix issue: Wrong duration for DB transaction event on ROR 7.1 #92 * Added unit tests and restructured the code * Fix unit tests * Update continuous-build.yml (#97) the latest macos-14 supports arm only. This PR using the previous version of macos image to unblock the release. * Worked on the jj22ee's comment and added logic that convert in seconds only for rails 7.1 versions. * Conditionally handle for ruby 7.1 --------- Co-authored-by: Lei Wang <[email protected]>
1 parent 26ae7b0 commit 16d808f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/aws-xray-sdk/facets/rails/active_record.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ def record(transaction)
2727
subsegment = XRay.recorder.begin_subsegment name, namespace: 'remote'
2828
# subsegment is nil in case of context missing
2929
return if subsegment.nil?
30-
subsegment.start_time = transaction.time.to_f
30+
# Rails 7.1 introduced time measurement in milliseconds instead seconds of causing xray-sdk to report wrong duration for transaction calls.
31+
# This is being handled in rails 7.2 and later. https://github.com/rails/rails/pull/50779
32+
subsegment.start_time = (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.time.to_f/1000 : transaction.time.to_f
3133
subsegment.sql = sql
32-
XRay.recorder.end_subsegment end_time: transaction.end.to_f
34+
XRay.recorder.end_subsegment end_time: (::Rails::VERSION::MAJOR == 7 and ::Rails::VERSION::MINOR == 1) ? transaction.end.to_f/1000 : transaction.end.to_f
3335
end
3436

3537
private

0 commit comments

Comments
 (0)