Skip to content

Commit

Permalink
Fix issue: Wrong duration for DB transaction event on ROR 7.1 #92 (#96)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ibnjunaid and wangzlei authored Aug 23, 2024
1 parent 26ae7b0 commit 16d808f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/aws-xray-sdk/facets/rails/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16d808f

Please sign in to comment.