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

Fix sentry-rails' controller span nesting #1973

Merged
merged 4 commits into from
Jan 19, 2023
Merged

Fix sentry-rails' controller span nesting #1973

merged 4 commits into from
Jan 19, 2023

Conversation

st0012
Copy link
Collaborator

@st0012 st0012 commented Dec 31, 2022

As described in #1899, the controller span's nesting is not correct because we record it through ActiveSupport instrumentation.

So this PR I did a few things:

  1. Make sure Span#with_child_span finishes the span properly when exceptions occurred, so users don't have to add boilerplate code in every call.
    • @sl0thentr0py I probably should make an isolated PR for this. Wdyt?
  2. Use Sentry.with_child_span around Rails' controller action so spans generated during actions can be attached to the controller span.
  3. Deprecate (not remove) the ActionControllerSubscriber. This is because tracing subscribers are public classes and removing them should be considered a breaking change.

Fixes #1899

@st0012 st0012 added this to the 5.8.0 milestone Dec 31, 2022
@st0012 st0012 self-assigned this Dec 31, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2022

Codecov Report

Base: 98.61% // Head: 98.61% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (ced34ad) compared to base (fb394a5).
Patch coverage: 98.03% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1973   +/-   ##
=======================================
  Coverage   98.61%   98.61%           
=======================================
  Files         157      157           
  Lines        9880     9902   +22     
=======================================
+ Hits         9743     9765   +22     
  Misses        137      137           
Impacted Files Coverage Δ
sentry-rails/lib/sentry/rails/configuration.rb 100.00% <ø> (ø)
...y-rails/lib/sentry/rails/controller_transaction.rb 93.75% <91.66%> (-6.25%) ⬇️
...ntry/rails/tracing/action_controller_subscriber.rb 100.00% <100.00%> (ø)
...ntry-rails/spec/sentry/rails/configuration_spec.rb 100.00% <100.00%> (ø)
...rails/tracing/action_controller_subscriber_spec.rb 100.00% <100.00%> (ø)
...entry/rails/tracing/action_view_subscriber_spec.rb 100.00% <100.00%> (ø)
...ry/rails/tracing/active_storage_subscriber_spec.rb 94.87% <100.00%> (ø)
sentry-rails/spec/sentry/rails/tracing_spec.rb 99.42% <100.00%> (+0.02%) ⬆️
sentry-ruby/lib/sentry/breadcrumb.rb 100.00% <0.00%> (+3.70%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sl0thentr0py
Copy link
Member

sl0thentr0py commented Jan 5, 2023

I probably should make an isolated PR for this. Wdyt?

Yep let's make this a separate change.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one question

sentry-rails/lib/sentry/rails/controller_transaction.rb Outdated Show resolved Hide resolved
@st0012 st0012 force-pushed the fix-#1899 branch 2 times, most recently from ced34ad to 4c4cdb9 Compare January 9, 2023 11:31
This makes sure all spans generated inside the controller call will be attached
under the controller span instead of the request span.
Now we wrap controller action inside `Sentry.with_child_span`, we don't need
to register the `ActionControllerSubscriber` anymore.

However, we still can't remove it because users may reference the constant
directly when customizing the tracing subscribers config.
begin
result = yield
ensure
child_span.set_http_status(response.status)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we guard for response being nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Rails, the controller's request and response object are all generated at the beginning of the request. So in this case, we don't need to worry about it being nil 🙂

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, see comment and ignore if not needed

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

Successfully merging this pull request may close these issues.

Span nesting for controller action incorrect
3 participants