Skip to content

ref(tracing): Remove mark measurements #5605

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

Merged
merged 1 commit into from
Aug 19, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sentryTest('should capture a FID vital.', async ({ browserName, getLocalTestPath

expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.fid?.value).toBeDefined();
expect(eventData.measurements?.['mark.fid']?.value).toBeDefined();

const fidSpan = eventData.spans?.filter(({ description }) => description === 'first input delay')[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ sentryTest('should capture FP vital.', async ({ browserName, getLocalTestPath, p
expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.fp?.value).toBeDefined();

expect(eventData.measurements?.['mark.fp']?.value).toBeDefined();

const fpSpan = eventData.spans?.filter(({ description }) => description === 'first-paint')[0];

expect(fpSpan).toBeDefined();
Expand All @@ -32,8 +30,6 @@ sentryTest('should capture FCP vital.', async ({ getLocalTestPath, page }) => {
expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.fcp?.value).toBeDefined();

expect(eventData.measurements?.['mark.fcp']?.value).toBeDefined();

const fcpSpan = eventData.spans?.filter(({ description }) => description === 'first-contentful-paint')[0];

expect(fcpSpan).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ sentryTest('should capture a LCP vital with element details.', async ({ browserN

expect(eventData.measurements).toBeDefined();
expect(eventData.measurements?.lcp?.value).toBeDefined();
expect(eventData.measurements?.['mark.lcp']?.value).toBeDefined();

expect(eventData.tags?.['lcp.element']).toBe('body > img');
expect(eventData.tags?.['lcp.size']).toBe(107400);
Expand Down
17 changes: 8 additions & 9 deletions packages/tracing/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ function _trackLCP(reportAllChanges: boolean): void {
return;
}

const timeOrigin = msToSec(browserPerformanceTimeOrigin as number);
const startTime = msToSec(entry.startTime);
__DEBUG_BUILD__ && logger.log('[Measurements] Adding LCP');
_measurements['lcp'] = { value: metric.value, unit: 'millisecond' };
_measurements['mark.lcp'] = { value: timeOrigin + startTime, unit: 'second' };
_lcpEntry = entry as LargestContentfulPaint;
}, reportAllChanges);
}
Expand Down Expand Up @@ -147,7 +144,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
case 'mark':
case 'paint':
case 'measure': {
const startTimestamp = _addMeasureSpans(transaction, entry, startTime, duration, timeOrigin);
_addMeasureSpans(transaction, entry, startTime, duration, timeOrigin);

// capture web vitals
const firstHidden = getVisibilityWatcher();
Expand All @@ -157,12 +154,10 @@ export function addPerformanceEntries(transaction: Transaction): void {
if (entry.name === 'first-paint' && shouldRecord) {
__DEBUG_BUILD__ && logger.log('[Measurements] Adding FP');
_measurements['fp'] = { value: entry.startTime, unit: 'millisecond' };
_measurements['mark.fp'] = { value: startTimestamp, unit: 'second' };
}
if (entry.name === 'first-contentful-paint' && shouldRecord) {
__DEBUG_BUILD__ && logger.log('[Measurements] Adding FCP');
_measurements['fcp'] = { value: entry.startTime, unit: 'millisecond' };
_measurements['mark.fcp'] = { value: startTimestamp, unit: 'second' };
}
break;
}
Expand Down Expand Up @@ -220,14 +215,18 @@ export function addPerformanceEntries(transaction: Transaction): void {
_measurements[name].value = normalizedValue;
});

if (_measurements['mark.fid'] && _measurements['fid']) {
const fidMark = _measurements['mark.fid'];
if (fidMark && _measurements['fid']) {
// create span for FID
_startChild(transaction, {
description: 'first input delay',
endTimestamp: _measurements['mark.fid'].value + msToSec(_measurements['fid'].value),
endTimestamp: fidMark.value + msToSec(_measurements['fid'].value),
op: 'web.vitals',
startTimestamp: _measurements['mark.fid'].value,
startTimestamp: fidMark.value,
});

// Delete mark.fid as we don't want it to be part of final payload
delete _measurements['mark.fid'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to delete it at the end here? Can't we just remove the line that sets mark.fid on _measurements?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, this is kind of a nit. It's being used to calculate the duration of the FID span but the way we're doing it now with this pattern seems a bit weird to me

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it's not the cleanest, but it is the most bundle size efficient to keep it in the same object instead of constructing a new variable.

tbh it's even worth considering if the FID span is that valuable - i don't really think it is, but that's a convo for another time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, keeping the bundle size down is important!

Agreed on the lack of value of the FID span, I think it is redundant since we're already saving it as a measurement, but yes we can discuss more on this later

}

// If FCP is not recorded we should not record the cls value
Expand Down