Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ttfd): Use TTID end timestamp when TTFD should be updated with an earlier timestamp #3869

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add missing logs to dropped App Start spans ([#3861](https://github.com/getsentry/sentry-react-native/pull/3861))
- Make all options of `startTimeToInitialDisplaySpan` optional ([#3867](https://github.com/getsentry/sentry-react-native/pull/3867))
- Add Span IDs to Time to Display debug logs ([#3868](https://github.com/getsentry/sentry-react-native/pull/3868))
- Use TTID end timestamp when TTFD should be updated with an earlier timestamp ([#3869](https://github.com/getsentry/sentry-react-native/pull/3869))

### Dependencies

Expand Down
7 changes: 6 additions & 1 deletion src/js/tracing/timetodisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ function updateFullDisplaySpan(frameTimestampSeconds: number, passedInitialDispl
return;
}

span.end(frameTimestampSeconds);
if (initialDisplayEndTimestamp > frameTimestampSeconds) {
logger.warn(`[TimeToDisplay] Using initial display end. Full display end frame timestamp is before initial display end.`);
span.end(initialDisplayEndTimestamp);
} else {
span.end(frameTimestampSeconds);
}

span.setStatus('ok');
logger.debug(`[TimeToDisplay] ${spanJSON.description} (${spanJSON.span_id}) span updated with end timestamp.`);
Expand Down
36 changes: 36 additions & 0 deletions test/tracing/timetodisplay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,42 @@ describe('TimeToDisplay', () => {
expect(spanToJSON(fullDisplaySpan!).timestamp).toEqual(initialDisplayEndTimestampMs / 1_000);
});

test('full display which ended before but processed after initial display is extended to initial display end', async () => {
const fullDisplayEndTimestampMs = secondInFutureTimestampMs();
const initialDisplayEndTimestampMs = secondInFutureTimestampMs() + 500;
const [initialDisplaySpan, fullDisplaySpan, activeSpan] = startSpanManual(
{
name: 'Root Manual Span',
startTime: secondAgoTimestampMs(),
},
(activeSpan: Span | undefined) => {
const initialDisplaySpan = startTimeToInitialDisplaySpan();
const fullDisplaySpan = startTimeToFullDisplaySpan();

const timeToDisplayComponent = TestRenderer.create(<><TimeToInitialDisplay record={false} /><TimeToFullDisplay record={true}/></>);
timeToDisplayComponent.update(<><TimeToInitialDisplay record={true} /><TimeToFullDisplay record={true} /></>);

emitNativeInitialDisplayEvent(initialDisplayEndTimestampMs);
emitNativeFullDisplayEvent(fullDisplayEndTimestampMs);

activeSpan?.end();
return [initialDisplaySpan, fullDisplaySpan, activeSpan];
},
);

await jest.runOnlyPendingTimersAsync();
await client.flush();

expectFinishedInitialDisplaySpan(initialDisplaySpan, activeSpan);
expectFinishedFullDisplaySpan(fullDisplaySpan, activeSpan);

expectInitialDisplayMeasurementOnSpan(client.event!);
expectFullDisplayMeasurementOnSpan(client.event!);

expect(spanToJSON(initialDisplaySpan!).timestamp).toEqual(initialDisplayEndTimestampMs / 1_000);
expect(spanToJSON(fullDisplaySpan!).timestamp).toEqual(initialDisplayEndTimestampMs / 1_000);
});

test('consequent renders do not update display end', async () => {
const initialDisplayEndTimestampMs = secondInFutureTimestampMs();
const fullDisplayEndTimestampMs = secondInFutureTimestampMs() + 500;
Expand Down
Loading