fix(tracing): Skip native frames and stall tracking for unsampled spans#5842
Merged
fix(tracing): Skip native frames and stall tracking for unsampled spans#5842
Conversation
The NativeFrames and StallTracking integrations performed their full work (native bridge calls, 50ms polling loop) regardless of whether the span would be sampled, unlike the Profiling integration which already checks spanIsSampled() correctly. With tracesSampleRate: 0.2, this meant 80% of navigation spans triggered unnecessary fetchNativeFrames() bridge calls and stall tracking loop activations. On low-end devices these operations are significantly more expensive and contribute to the performance overhead reported in #5665. The fix adds a spanIsSampled() guard at the entry of fetchStartFramesForSpan in NativeFrames and _onSpanStart in StallTracking. Since end-frame fetching already bails when no start frames are found, the single guard in fetchStartFramesForSpan covers both start and end for NativeFrames. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
Contributor
lucas-zimerman
approved these changes
Mar 19, 2026
Collaborator
lucas-zimerman
left a comment
There was a problem hiding this comment.
Sounds good to me, we can move with the changelog later.
This was referenced Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
Add a
spanIsSampled()guard toNativeFramesandStallTracking, consistent with howProfilingalready handles this.fetchStartFramesForSpan): returns early for unsampled spans, skipping allfetchNativeFrames()native bridge calls. SincefetchEndFramesForSpanalready bails when no start frames are found, a single guard covers both._onSpanStart): returns early for unsampled root spans, skipping the 50ms JS polling loop entirely.💡 Motivation and Context
Both integrations were doing their full work regardless of sampling decision. With
tracesSampleRate: 0.2, 80% of navigation spans were triggering unnecessary native bridge calls and stall tracking loop activations. On low-end devices (reported in #5665) these are measurably expensive.The
Profilingintegration already checksspanIsSampled()correctly — this brings the other two integrations in line.💚 How did you test it?
Added one new test per integration:
NativeFramesInstrumentation > unsampled spans > does not fetch native frames for unsampled spans— verifiesNATIVE.fetchNativeFramesis never called whentracesSampleRate: 0StallTracking > does not track stalls for unsampled spans— verifies no stall measurements are attached whentracesSampleRate: 0All 33 tests pass (31 existing + 2 new).
📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
Part of a broader investigation into
reactNavigationIntegrationperformance on low-end devices (#5665).