feat: Always stream INP and remove standalone v1 spans#22517
Conversation
size-limit report 📦
|
e956bd9 to
8fb2e6d
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bd7695f. Configure here.
96516ba to
09e3cbd
Compare
INP is now always emitted as a v2 web vital span. With span streaming enabled it rides the streaming pipeline; with streaming disabled it overrides the static trace lifecycle for itself and still streams (sent directly via `captureSpan` + `createStreamedSpanEnvelope`, since it is a single span per interaction), because it reports late and would otherwise be dropped. INP was the last user of the standalone v1 span mechanism, so that is removed entirely: the `experimental.standalone` option, the `_isStandaloneSpan` handling and self-send path in `SentrySpan`, the `createSpanEnvelope` wire format, and the `SpanEnvelope`/`SpanItem` types and their exports from `@sentry/core` and `@sentry/types`. Also dedupes the v2 `SpanContainerItem` construction shared by `createStreamedSpanEnvelope` and gen_ai span extraction into `createSpanContainerItem`.
…e attribute - MIGRATION.md: note the removal of `createSpanEnvelope` and the `SpanEnvelope` / `SpanItem` types from `@sentry/core`. - E2E: assert `browser.web_vital.inp.value` on the INP span (the new payload field) in the react-17 / react-router-6 / react-router-7-spa / react-router-8-spa apps.
Under the static (transaction) trace lifecycle, force-streaming the INP span made it an ordinary tree span, so it was also swept into the pageload transaction (or emitted as its own transaction when parentless), double-sending INP. Reinstate a per-span standalone flag in core that sends the span on its own as a v2 streamed span and excludes it from transaction assembly. INP sets the flag when span streaming is disabled. Every piece of the mechanism is tagged with a TODO(standalone) marker for removal once the static trace lifecycle is dropped and every span streams on its own.
09e3cbd to
887230c
Compare
Lms24
left a comment
There was a problem hiding this comment.
Nice! Really glad to see v1 standalone spans being gone! I think the bundle size hit ammortizes with span streaming becoming the default anyway (i.e. captureSpan will be in all bundles by default), so this should be fine.
Also, keeping the experimental.standalone option around seems reasonable to me as long as we need to support transactions.
The always-streamed INP migration had narrowed the INP web-vital tests to a few spot checks. This brings back exhaustive assertions in the v2 streamed-span shape: the full envelope header (DSC + item header) and the complete span (attributes, is_segment, status, parent linkage, timestamps) across the browser integration suites, and comprehensive span assertions across the react E2E apps.
Restore the guard that skips standalone spans in the idle span's `spanStart` activity tracker. A standalone span is sent on its own and must not participate in its parent's lifecycle, so it should never push activity onto or prolong an open idle span. This can still happen with experimental interaction idle spans. Restores the accompanying test that was dropped alongside the guard.
Drop the redundant `client` and `!_isStandaloneSpan` re-checks: emit `spanEnd` via optional chaining, let the standalone branch own its early return with guard-style returns, and emit `afterSpanEnd` only on the non-standalone path. No behavior change.
| end_timestamp: this._endTime ?? this._startTime, | ||
| is_segment: this._isStandaloneSpan || this === getRootSpan(this), | ||
| is_segment: this === getRootSpan(this), |
There was a problem hiding this comment.
Bug: Standalone INP spans with a parent will have is_segment: false incorrectly set because the _isStandaloneSpan check was removed from the getStreamedSpanJSON method.
Severity: MEDIUM
Suggested Fix
Restore the check for this._isStandaloneSpan in the getStreamedSpanJSON method. The logic for is_segment should be is_segment: this._isStandaloneSpan || this === getRootSpan(this) to correctly identify standalone spans as segments, even when they have a parent in the local span tree.
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/core/src/tracing/sentrySpan.ts#L327-L328
Potential issue: In `getStreamedSpanJSON`, the logic for determining if a span is a
segment was changed to `is_segment: this === getRootSpan(this)`, removing a check for
`this._isStandaloneSpan`. This causes an issue for standalone INP (Interaction to Next
Paint) spans that are created with a `parentSpan`, which occurs when span streaming is
disabled. For such spans, `getRootSpan(this)` returns the parent's root, causing `this
=== getRootSpan(this)` to evaluate to `false`. Consequently, `is_segment` is incorrectly
set to `false`, and crucial segment-level processing like applying scope attributes and
SDK metadata is skipped, leading to incomplete span data being sent.
There was a problem hiding this comment.
lol, same reasoning as above

INP is now always emitted as a v2 web vital span. With span streaming enabled it rides the streaming pipeline as before. With span streaming disabled (
traceLifecycle: 'static') INP overrides the static lifecycle for itself and still streams, because it reports late and would otherwise be dropped as a late child with nothing to carry it.The bundle size increase is due to the bytes that now have to live in core without being tree-shaken which re-uses some of the stuff gen_ai uses to send out independent v2 spans. It's only a few bytes, the browser bundle savings are more significant.
Note that there is still a bunch of
standalonereferences, those are needed to skip the span from becoming its own transaction in static lifecycles, it can be removed once we drop those in v12.