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 · 3 comments
Open

[ActiveRecord] Add Attributes for Async Queries #1219

arielvalentin opened this issue Oct 31, 2024 · 3 comments
Labels
feature New feature or request instrumentation keep Ensures stale-bot keeps this issue/PR open

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

Copy link
Contributor

github-actions bot commented Dec 1, 2024

👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this issue will be closed eventually by the stale bot.

@github-actions github-actions bot added the stale Marks an issue/PR stale label Dec 1, 2024
@arielvalentin arielvalentin added keep Ensures stale-bot keeps this issue/PR open and removed stale Marks an issue/PR stale labels Dec 1, 2024
@zvkemp
Copy link

zvkemp commented Dec 13, 2024

I can work on this.

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 keep Ensures stale-bot keeps this issue/PR open
Projects
None yet
Development

No branches or pull requests

3 participants