Conversation
… requiring a parent
size-limit report 📦
|
| const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx); | ||
| const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx; | ||
|
|
||
| if (shouldSkipSpan) { | ||
| getClient()?.recordDroppedEvent('no_parent_span', 'span'); | ||
| } |
There was a problem hiding this comment.
Maybe this could be made a bit more robust. Right now it's checking shouldSkipSpan but the value of the variable could depend on something else than onlyIfParent in the future. Then this would be wrong.
The test also only check for dropped events and not necessarily that this resulted because of a missing parent span.
There was a problem hiding this comment.
Yeah I guess we could inline the variable or name it a bit more precise, unless you had something else in mind?
There was a problem hiding this comment.
I added some additional tests and changed the variable name to a more descriptive one (missingRequiredParent) and not behaviorial one. shouldSkipSpan could include any condition why we skip spans.
It was not really possible to change the general structure here.
| | 'ignored' | ||
| | 'invalid'; | ||
| | 'invalid' | ||
| | 'no_parent_span'; |
There was a problem hiding this comment.
do we need a change in relay for this?
| const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx); | ||
| const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx; | ||
|
|
||
| if (shouldSkipSpan) { | ||
| getClient()?.recordDroppedEvent('no_parent_span', 'span'); | ||
| } |
There was a problem hiding this comment.
Yeah I guess we could inline the variable or name it a bit more precise, unless you had something else in mind?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2b11222. Configure here.
Co-authored-by: Nicolas Hrubec <nicolas.hrubec@outlook.com>
| getClient()?.recordDroppedEvent('no_parent_span', 'span'); | ||
| } | ||
|
|
There was a problem hiding this comment.
Bug: http.client spans without a parent are counted as dropped twice: once in startInactiveSpan and again in the SentrySampler, leading to inflated metrics.
Severity: MEDIUM
Suggested Fix
Prevent the double-counting of dropped events. One approach is to remove the recordDroppedEvent('no_parent_span', 'span') call from startInactiveSpan for http.client spans, allowing the SentrySampler to handle this case exclusively as it did previously.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/opentelemetry/src/trace.ts#L162-L164
Potential issue: When an `http.client` span is created with `onlyIfParent: true` and no
active parent span exists, the new logic in `startInactiveSpan` records a
`'no_parent_span'` dropped event. However, the span creation process continues, and the
`SentrySampler` is also invoked. The sampler contains separate logic to detect and
record a dropped event for `http.client` spans without a local parent. This results in
the same dropped span being counted twice, which will inflate the `no_parent_span`
outcome metrics.
Did we get this right? 👍 / 👎 to inform future reviews.

This PR adds reporting a client discard outcome for spans we skip because they require a parent span to be active. This happens when
onlyIfParent: trueis set when starting spans, or in custom logic forhttp.clientspans. With this PR, we should now get a much clearer picture of how many spans users are missing out on.In span streaming, we'll always emit them (see #17932) spans.
closes https://linear.app/getsentry/issue/SDK-1123/add-client-report-outcome-for-dropped-spans-because-of-missing-parent