Skip to content

Commit 8008d2b

Browse files
committed
ref(browser-utils): Align standalone LCP span attribute setting with pageload span LCP attributes
1 parent 64904f5 commit 8008d2b

File tree

1 file changed

+15
-6
lines changed
  • packages/browser-utils/src/metrics

1 file changed

+15
-6
lines changed

packages/browser-utils/src/metrics/lcp.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,21 @@ function sendStandaloneLcpSpan(lcpValue: number, entry: LargestContentfulPaint |
105105
};
106106

107107
if (entry) {
108-
attributes['lcp.element'] = htmlTreeAsString(entry.element);
109-
attributes['lcp.id'] = entry.id;
110-
attributes['lcp.url'] = entry.url;
111-
attributes['lcp.loadTime'] = entry.loadTime;
112-
attributes['lcp.renderTime'] = entry.renderTime;
113-
attributes['lcp.size'] = entry.size;
108+
entry.element && (attributes['lcp.element'] = htmlTreeAsString(entry.element));
109+
entry.id && (attributes['lcp.id'] = entry.id);
110+
111+
// Trim URL to the first 200 characters.
112+
entry.url && (attributes['lcp.url'] = entry.url.trim().slice(0, 200));
113+
114+
// loadTime is the time of LCP that's related to receiving the LCP element response..
115+
entry.loadTime != null && (attributes['lcp.loadTime'] = entry.loadTime);
116+
117+
// renderTime is loadTime + rendering time
118+
// it's 0 if the LCP element is loaded from a 3rd party origin that doesn't send the
119+
// `Timing-Allow-Origin` header.
120+
entry.renderTime != null && (attributes['lcp.renderTime'] = entry.renderTime);
121+
122+
entry.size && (attributes['lcp.size'] = entry.size);
114123
}
115124

116125
const span = startStandaloneWebVitalSpan({

0 commit comments

Comments
 (0)