Skip to content

Commit 8dd26dc

Browse files
fix(ttd): Gracefully handle missing parentSpanId when measuring TTID/TTFD on iOS (#4881)
1 parent f963533 commit 8dd26dc

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- crashedLastRun now returns the correct value ([#4829](https://github.com/getsentry/sentry-react-native/pull/4829))
4444
- Use engine-specific promise rejection tracking ([#4826](https://github.com/getsentry/sentry-react-native/pull/4826))
4545
- Fixes Feedback Widget accessibility issue on iOS ([#4739](https://github.com/getsentry/sentry-react-native/pull/4739))
46+
- Measuring TTID or TTFD could cause a crash when `parentSpanId` was removed ([#4881](https://github.com/getsentry/sentry-react-native/pull/4881))
4647

4748
### Dependencies
4849

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryOnDrawReporterTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,30 @@ final class RNSentryOnDrawReporterTests: XCTestCase {
119119

120120
XCTAssertNil(RNSentryTimeToDisplay.pop(for: ttidPrefix + spanId))
121121
}
122+
123+
func testFullDisplayEmitNewFrameCallbackHandlesMissingParentSpanId() {
124+
let reporter = RNSentryOnDrawReporterView.createWithMockedListener()
125+
126+
// We call the callback manually in this test to simulate a change between
127+
// start of listening for next frame and the next frame render
128+
let emitNewFrameCallback = reporter!.createEmitNewFrameEvent()
129+
130+
reporter!.fullDisplay = true
131+
reporter!.parentSpanId = nil
132+
133+
emitNewFrameCallback!(1)
134+
}
135+
136+
func testInitialDisplayEmitNewFrameCallbackHandlesMissingParentSpanId() {
137+
let reporter = RNSentryOnDrawReporterView.createWithMockedListener()
138+
139+
// We call the callback manually in this test to simulate a change between
140+
// start of listening for next frame and the next frame render
141+
let emitNewFrameCallback = reporter!.createEmitNewFrameEvent()
142+
143+
reporter!.initialDisplay = true
144+
reporter!.parentSpanId = nil
145+
146+
emitNewFrameCallback!(1)
147+
}
122148
}

packages/core/ios/RNSentryOnDrawReporter.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ - (RNSentryEmitNewFrameEvent)createEmitNewFrameEvent
4242
return ^(NSNumber *newFrameTimestampInSeconds) {
4343
self->isListening = NO;
4444

45+
if (![_parentSpanId isKindOfClass:[NSString class]]) {
46+
return;
47+
}
48+
4549
if (self->_fullDisplay) {
4650
[RNSentryTimeToDisplay
4751
putTimeToDisplayFor:[@"ttfd-" stringByAppendingString:self->_parentSpanId]

0 commit comments

Comments
 (0)