Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong duration for DB transaction event #92

Open
wangzlei opened this issue Jul 7, 2023 · 2 comments
Open

Wrong duration for DB transaction event #92

wangzlei opened this issue Jul 7, 2023 · 2 comments

Comments

@wangzlei
Copy link
Contributor

wangzlei commented Jul 7, 2023

[Steps to reproduce the issue]

  • Create a Ruby on rails application with the X-Ray SDK for Ruby middleware [3] to send requests to the Database.
    • Create a Model and a corresponding Controller.
    • Define routing URL pattern corresponding to the Controller.
  • Start the X-Ray daemon.
  • Send a request to the created application.
  • Confirm the the time duration for the trace in the X-Ray console.

As a result, the start_time of a subsegment during a DB operation was set to a time in the distant future.

[Investigation]

@duckworth
Copy link

Digging deeper into this and it seems In Rails version 6, the ActiveSupport::Notifications module used Concurrent.monotonic_time to record times, which effectively reported times in seconds. In Rails 7 and higher they shifted to use Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond), which provides time measurements in milliseconds for more granular and precise timing of events.

https://github.com/rails/rails/blob/6-1-stable/activesupport/lib/active_support/notifications/instrumenter.rb#L129C10-L129C36
vs
https://github.com/rails/rails/blob/f12ae4448477a57c6fdac39039ac9fd60ba878bf/activesupport/lib/active_support/notifications/instrumenter.rb#L154

This issue is causing any DB related traces to show incorrect durations in the XRay console.

ibnjunaid added a commit to ibnjunaid/aws-xray-sdk-ruby that referenced this issue Aug 16, 2024
jj22ee pushed a commit that referenced this issue Aug 23, 2024
* 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 <66336933+wangzlei@users.noreply.github.com>
@duckworth
Copy link

@wangzlei @jj22ee It looks like Rails actually backported a fix to 7.1.4 now https://github.com/rails/rails/releases/tag/v7.1.4

Fix ActiveSupport::Notifications.publish_eventto preserve units.
This solves the incorrect reporting of time spent running Active Record
asynchronous queries (by a factor 1000).
Jean Boussier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants