fix(tracing): Fix native frames measurements dropped for idle transactions#5813
Open
fix(tracing): Fix native frames measurements dropped for idle transactions#5813
Conversation
…tions The NativeFrames integration was dropping transaction-level frame measurements (frames_total, frames_slow, frames_frozen) for all idle transactions because the fallback child span end frames were either unavailable or had mismatched timestamps when processEvent ran. Three issues fixed: - Race condition: child span end frames stored after async awaits, so processEvent could run before data was available. Now stores a Promise immediately before any awaits. - Timestamp mismatch: used wall-clock time (timestampInSeconds) instead of actual span timestamp (spanToJSON), causing isClose check to fail when comparing against the trimmed event.timestamp. - Concurrent transaction interference: single global variable overwritten by any transaction's child spans. Now scoped per root span using AsyncExpiringMap. Co-Authored-By: Claude Opus 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
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
@sentry review |
Contributor
Author
|
@claude review |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| childEndFramesPromise | ||
| .then(frames => ({ timestamp: spanTimestamp, nativeFrames: frames })) | ||
| .then(undefined, error => { | ||
| debug.log(`[${INTEGRATION_NAME}] Error while fetching child span end frames.`, error); |
Collaborator
There was a problem hiding this comment.
Won't this and line 195 generated duplicated error logs?
1. Line 138: "Error while fetching child span end frames."
2. Line 195: "Error while capturing end frames for span ${spanId}."
Collaborator
|
Q: |
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
The NativeFrames integration was silently dropping transaction-level frame measurements (
frames_total,frames_slow,frames_frozen) for idle transactions with the warning:This affected all idle transactions (navigation-based performance monitoring), causing slow/frozen frame metrics to be missing from the Performance pages.
Three issues fixed in the child span end frames fallback path of
processEvent:Race condition: Child span end frames were stored in the map only after two async
awaits completed (_spanToNativeFramesAtStartMap.get()andfetchNativeFrames()). IfprocessEventran before those awaits finished, the fallback data was unavailable. Now stores aPromiseimmediately before any awaits, matching the pattern used by the root span end frames path.Timestamp mismatch: Used
timestampInSeconds()(wall-clock time) for the child span end timestamp, but compared it againstevent.timestampwhich is the span's actual end time. For idle transactions whereevent.timestampis trimmed to the last child span's end time, the wall-clock time atspanEndevent firing could differ. Now usesspanToJSON(span).timestamp— the same timestamp source the idle proxy trims to.Concurrent transaction interference: The fallback was a single global variable (
_lastChildSpanEndFrames) overwritten by any transaction's child spans. Now scoped per root span usingAsyncExpiringMapkeyed by root span ID, with a 60s TTL to survive idle timeouts + processing delays.Bonus: child spans now reuse the same
fetchNativeFrames()promise for both the fallback map and span attributes, eliminating a redundant native bridge call per child span.💡 Motivation and Context
Reported by a customer on SDK v6.15.1 seeing 100% of idle transactions missing slow/frozen frame measurements. The issue exists on both iOS and Android and affects all SDK versions (v6 and v7/v8) since the
processEventfallback logic has not changed.Related: #4723
💚 How did you test it?
falls back to last child span end frames when root span end timestamp does not match event timestamp (idle transaction trim)— simulates idle transaction trimming by shiftingevent.timestampback to child span end time and advancing mock time for root span end, verifying the fallback path produces correct measurements.📝 Checklist
sendDefaultPIIis enabled🔮 Next steps