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

[ActiveRecord] Add Attributes for Async Queries #1219

Open
arielvalentin opened this issue Oct 31, 2024 · 1 comment
Open

[ActiveRecord] Add Attributes for Async Queries #1219

arielvalentin opened this issue Oct 31, 2024 · 1 comment
Labels
feature New feature or request instrumentation

Comments

@arielvalentin
Copy link
Collaborator

ActiveRecord 7.1 introduced async query methods1, which leverages concurrency primitives via Promise API to defer executing queries.

We would like to enrich ActiveRecord related spans to know whether or not they were executed from the async context.

Additional Notes

The sql.active_record notification payload includes a async attribute:
https://github.com/rails/rails/blob/616d3a7675c18ae2d38d3116de47e2e7308cfbd8/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb#L1135

We may be able to enrich the ActiveRecord span and amend it as a Shared DB attribute for the driver itself however we do not currently use notifications in this instrumentation.

Worst case scenario, we monkey patch existing async methods, concurrency primitives.

Footnotes

  1. https://github.com/rails/rails/pull/44446

@arielvalentin arielvalentin added feature New feature or request instrumentation labels Oct 31, 2024
@bensheldon
Copy link
Contributor

Thank you for opening this! 🙇🏻

It would also be great if we could include the lock_wait attribute too, which represents how much time is spent in the foreground waiting for the query to complete (in a true async query, it would be 0.0ms):

https://github.com/rails/rails/blob/df9912116b29423b5bde3771b9829447a07d3f6c/activerecord/lib/active_record/log_subscriber.rb#L23-L24

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

No branches or pull requests

2 participants