Nested childs for Active Record SQL queries#1723
Nested childs for Active Record SQL queries#1723pbernery wants to merge 1 commit intogetsentry:masterfrom
Conversation
st0012
left a comment
There was a problem hiding this comment.
I generally agree with this idea. But I'm not sure if it could cause problems to some users?
In my other project, there could be many n+1 queries across different abstraction layers in problematic endpoints. In those cases, I'm worry that nesting will make the spans harder to view? (Of course, you can also argue that it's an UI design issue).
@sl0thentr0py Do you think the above would be an issue? Is there any recommendation on nesting spans in integrations?
| return unless current_span && current_span.sampled | ||
|
|
||
| span = current_span.start_child(**options) | ||
| Sentry.get_current_scope.set_span(span) |
There was a problem hiding this comment.
I think this and the get_current_scope are unnecessary. Aren't they the same scope as the scope local?
| current_span = scope.get_span | ||
| return unless current_span && current_span.sampled | ||
|
|
||
| span = current_span.start_child(**options) |
There was a problem hiding this comment.
We can use with_child_span(&block) here:
sentry-ruby/sentry-ruby/lib/sentry/span.rb
Lines 151 to 166 in 341b66e
|
@st0012 I think the correct semantic is nesting, irrespective of UI concerns. If the DB query runs within some other span's context, it should certainly not go under the root span but be nested at the appropriate level. |
|
Thanks for both your feedbacks. So, with @st0012 suggestions applied, do you believe this PR could be merged as-is then, or should more work be done? The changes have made works for SQL transactions, but not for Redis transactions, so I guess the equivalent should be applied on the Redis side. And maybe more services. But we could advance step by step: nest SQL first, then later Redis, etc. |
Codecov Report
@@ Coverage Diff @@
## master #1723 +/- ##
==========================================
- Coverage 98.41% 98.39% -0.02%
==========================================
Files 141 141
Lines 8004 8032 +28
==========================================
+ Hits 7877 7903 +26
- Misses 127 129 +2
Continue to review full report at Codecov.
|
|
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
|
So what do you think @sl0thentr0py @st0012? |
|
@pbernery the proposal is good but we can't merge the current code and without tests. |
|
Let me know if you plan to finish the PR, or I can make another one to address the issue as well. |
|
I think the SDK should actually provide a top-level helper like |
|
Hi Stan, sorry for the delayed response. |
|
Hey @st0012, just tested the Sentry.with_child_span and it looks like it's working great on our side. Thank you very much for this update :) |
|
@pbernery Thanks for catching that 👍 I've added another PR to address it. |
Currently, when nesting children (using
start_child), SQL queries, Redis commands, are not attached to the created span but are attached to the root span (or the transaction).This makes the span graph looks like this:
while I expect to have "db.sql.active_record" spans nested in parent spans.
I made some change in this PR that leads to the expected behaviour:
but I am not sure than calling
set_spanis the right approach, it changes the "current" span globally. This works when there is one nested branch but if there are multiple, this may not work as expected.The Redis spans have the same issue:

And I guess the issue is everywhere
Sentry.get_current_scope.get_transactionis used.There was a PR #1382 that fixed nested custom child. It fixed things for children created manually, and proposes to use a child to create another child, but how could events handled by Sentry use those child?