getsentry / sentry-ruby

Sentry SDK for Ruby
https://sentry.io/for/ruby
MIT License
927 stars 486 forks source link

Add query source support to `sentry-rails` #2313

Closed st0012 closed 2 months ago

st0012 commented 2 months ago

Closes #2242

This PR adds query source information to the tracing spans captured by sentry-rails's ActiveSupportSubscriber, which should be picked up by Sentry and displayed like:

Screenshot 2024-05-26 at 16 43 23

The implementation is inspired by Rails' ActiveRecord::LogSubscriber but doesn't depend on it.

There are several requirements for this feature to work:

And to reduce the feature's overhead, only queries that exceed config.rails.db_query_source_threshold_ms will have source recorded, which is set to 100ms by default.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 95.14563% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 98.66%. Comparing base (41ab3ba) to head (a47f0c2).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2313 +/- ## ======================================= Coverage 98.66% 98.66% ======================================= Files 205 205 Lines 13339 13422 +83 ======================================= + Hits 13161 13243 +82 - Misses 178 179 +1 ``` | [Components](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | Coverage Δ | | |---|---|---| | [sentry-ruby](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `99.03% <100.00%> (+0.01%)` | :arrow_up: | | [sentry-rails](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `97.42% <94.94%> (+0.05%)` | :arrow_up: | | [sentry-sidekiq](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `96.98% <ø> (ø)` | | | [sentry-resque](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `96.76% <ø> (-0.33%)` | :arrow_down: | | [sentry-delayed_job](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `98.91% <ø> (ø)` | | | [sentry-opentelemetry](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | `100.00% <ø> (ø)` | | | [Files](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | Coverage Δ | | |---|---|---| | [sentry-rails/lib/sentry/rails/configuration.rb](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313?src=pr&el=tree&filepath=sentry-rails%2Flib%2Fsentry%2Frails%2Fconfiguration.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry#diff-c2VudHJ5LXJhaWxzL2xpYi9zZW50cnkvcmFpbHMvY29uZmlndXJhdGlvbi5yYg==) | `97.43% <100.00%> (+0.29%)` | :arrow_up: | | [...try/rails/tracing/active\_record\_subscriber\_spec.rb](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313?src=pr&el=tree&filepath=sentry-rails%2Fspec%2Fsentry%2Frails%2Ftracing%2Factive_record_subscriber_spec.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry#diff-c2VudHJ5LXJhaWxzL3NwZWMvc2VudHJ5L3JhaWxzL3RyYWNpbmcvYWN0aXZlX3JlY29yZF9zdWJzY3JpYmVyX3NwZWMucmI=) | `100.00% <100.00%> (ø)` | | | [sentry-ruby/lib/sentry/span.rb](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313?src=pr&el=tree&filepath=sentry-ruby%2Flib%2Fsentry%2Fspan.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry#diff-c2VudHJ5LXJ1YnkvbGliL3NlbnRyeS9zcGFuLnJi) | `100.00% <100.00%> (ø)` | | | [...b/sentry/rails/tracing/active\_record\_subscriber.rb](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313?src=pr&el=tree&filepath=sentry-rails%2Flib%2Fsentry%2Frails%2Ftracing%2Factive_record_subscriber.rb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry#diff-c2VudHJ5LXJhaWxzL2xpYi9zZW50cnkvcmFpbHMvdHJhY2luZy9hY3RpdmVfcmVjb3JkX3N1YnNjcmliZXIucmI=) | `90.38% <88.63%> (+4.67%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/getsentry/sentry-ruby/pull/2313/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry)