Skip to content

fix(tracing): Skip native frames and stall tracking for unsampled spans#5842

Merged
antonis merged 2 commits intomainfrom
antonis/skip-native-frames
Mar 19, 2026
Merged

fix(tracing): Skip native frames and stall tracking for unsampled spans#5842
antonis merged 2 commits intomainfrom
antonis/skip-native-frames

Conversation

@antonis
Copy link
Contributor

@antonis antonis commented Mar 19, 2026

📢 Type of change

  • Bugfix

📜 Description

Add a spanIsSampled() guard to NativeFrames and StallTracking, consistent with how Profiling already handles this.

  • NativeFrames (fetchStartFramesForSpan): returns early for unsampled spans, skipping all fetchNativeFrames() native bridge calls. Since fetchEndFramesForSpan already bails when no start frames are found, a single guard covers both.
  • StallTracking (_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 Profiling integration already checks spanIsSampled() 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 — verifies NATIVE.fetchNativeFrames is never called when tracesSampleRate: 0
  • StallTracking > does not track stalls for unsampled spans — verifies no stall measurements are attached when tracesSampleRate: 0

All 33 tests pass (31 existing + 2 new).

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

Part of a broader investigation into reactNavigationIntegration performance on low-end devices (#5665).

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>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(tracing): Skip native frames and stall tracking for unsampled spans by antonis in #5842

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 6a3d7a9

Copy link
Contributor Author

@antonis antonis left a comment

Choose a reason for hiding this comment

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

I would suggest to skip the changelog for now and maybe add a changelog entry when all the improvements of #5665 are delivered. Happy to add it if you feel it is needed.

@antonis antonis marked this pull request as ready for review March 19, 2026 10:42
Copy link
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

Sounds good to me, we can move with the changelog later.

@antonis antonis enabled auto-merge (squash) March 19, 2026 14:43
@antonis antonis merged commit 4ff35e2 into main Mar 19, 2026
33 of 45 checks passed
@antonis antonis deleted the antonis/skip-native-frames branch March 19, 2026 14:50
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.

2 participants