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 <[email protected]>
@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

tetsu040e added a commit to enechange/aws-xray-sdk-ruby that referenced this issue Oct 15, 2024
* Add ECS metadata allowing cloudwatch-logs to be linked with traces (aws#93)

* First step

* Add comment

* Typo

* Copy logic of EC2 plugin for ECS

* Typo

* Back to symbols

* Copy paste all EC2 tests as starting point for ECS

* Comments

* Somewhat working ?

* Backword compatible with prevous feature when not 1.4

* Add hint for fargate 1.4 in case of errors

---------

Co-authored-by: Etienne Chabert <[email protected]>

* release 0.15.0 (aws#94)

* Update version for 0.15.0 release (aws#95)

* Update continuous-build.yml (aws#97)

the latest macos-14 supports arm only. 
This PR using the previous version of macos image to unblock the release.

* Fix issue: Wrong duration for DB transaction event  on ROR 7.1 aws#92 (aws#96)

* Fix issue: Wrong duration for DB transaction event  on ROR 7.1 aws#92

* Added unit tests and restructured the code

* Fix unit tests

* Update continuous-build.yml (aws#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]>

* Release 0.16.0 (aws#98)

---------

Co-authored-by: Chabert Etienne <[email protected]>
Co-authored-by: Etienne Chabert <[email protected]>
Co-authored-by: Prashant Srivastava <[email protected]>
Co-authored-by: Lei Wang <[email protected]>
Co-authored-by: Osama Bin Junaid <[email protected]>
Co-authored-by: Min Xia <[email protected]>
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