Skip to content

Commit ae11b64

Browse files
committed
Add CLS source details to standalone web vital spans for debugging
1 parent c37d4e5 commit ae11b64

File tree

3 files changed

+28
-17
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans
  • packages/browser-utils/src/metrics

3 files changed

+28
-17
lines changed

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ sentryTest('captures a "GOOD" CLS vital with its source as a standalone span', a
6868
transaction: expect.stringContaining('index.html'),
6969
'user_agent.original': expect.stringContaining('Chrome'),
7070
'sentry.pageload.span_id': expect.stringMatching(/[a-f0-9]{16}/),
71+
'cls.source.1': expect.stringContaining('body > div#content > p'),
7172
},
7273
description: expect.stringContaining('body > div#content > p'),
7374
exclusive_time: 0,
@@ -136,6 +137,7 @@ sentryTest('captures a "MEH" CLS vital with its source as a standalone span', as
136137
transaction: expect.stringContaining('index.html'),
137138
'user_agent.original': expect.stringContaining('Chrome'),
138139
'sentry.pageload.span_id': expect.stringMatching(/[a-f0-9]{16}/),
140+
'cls.source.1': expect.stringContaining('body > div#content > p'),
139141
},
140142
description: expect.stringContaining('body > div#content > p'),
141143
exclusive_time: 0,
@@ -202,6 +204,7 @@ sentryTest('captures a "POOR" CLS vital with its source as a standalone span.',
202204
transaction: expect.stringContaining('index.html'),
203205
'user_agent.original': expect.stringContaining('Chrome'),
204206
'sentry.pageload.span_id': expect.stringMatching(/[a-f0-9]{16}/),
207+
'cls.source.1': expect.stringContaining('body > div#content > p'),
205208
},
206209
description: expect.stringContaining('body > div#content > p'),
207210
exclusive_time: 0,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ function sendStandaloneClsSpan(clsValue: number, entry: LayoutShift | undefined,
106106
'sentry.pageload.span_id': pageloadSpanId,
107107
};
108108

109+
// Add CLS sources as span attributes to help with debugging layout shifts
110+
// See: https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift/sources
111+
if (entry?.sources) {
112+
entry.sources.forEach((source, index) => {
113+
attributes[`cls.source.${index + 1}`] = htmlTreeAsString(source.node);
114+
});
115+
}
116+
109117
const span = startStandaloneWebVitalSpan({
110118
name,
111119
transaction: routeName,

yarn.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26920,7 +26920,7 @@ string-template@~0.2.1:
2692026920
is-fullwidth-code-point "^3.0.0"
2692126921
strip-ansi "^6.0.1"
2692226922

26923-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
26923+
[email protected], "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
2692426924
version "4.2.3"
2692526925
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
2692626926
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -27030,6 +27030,13 @@ stringify-object@^3.2.1:
2703027030
dependencies:
2703127031
ansi-regex "^5.0.1"
2703227032

27033+
[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
27034+
version "6.0.1"
27035+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
27036+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
27037+
dependencies:
27038+
ansi-regex "^5.0.1"
27039+
2703327040
strip-ansi@^3.0.0:
2703427041
version "3.0.1"
2703527042
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
@@ -27051,13 +27058,6 @@ strip-ansi@^5.1.0, strip-ansi@^5.2.0:
2705127058
dependencies:
2705227059
ansi-regex "^4.1.0"
2705327060

27054-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
27055-
version "6.0.1"
27056-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
27057-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
27058-
dependencies:
27059-
ansi-regex "^5.0.1"
27060-
2706127061
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
2706227062
version "7.1.0"
2706327063
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -27193,7 +27193,7 @@ [email protected], stylus@^0.59.0:
2719327193
sax "~1.2.4"
2719427194
source-map "^0.7.3"
2719527195

27196-
sucrase@^3.27.0, sucrase@^3.35.0:
27196+
sucrase@^3.27.0, sucrase@^3.35.0, sucrase@getsentry/sucrase#es2020-polyfills:
2719727197
version "3.36.0"
2719827198
resolved "https://codeload.github.com/getsentry/sucrase/tar.gz/fd682f6129e507c00bb4e6319cc5d6b767e36061"
2719927199
dependencies:
@@ -29828,19 +29828,19 @@ wrangler@^3.67.1:
2982829828
string-width "^4.1.0"
2982929829
strip-ansi "^6.0.0"
2983029830

29831-
wrap-ansi@^6.0.1:
29832-
version "6.2.0"
29833-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
29834-
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==
29831+
wrap-ansi@7.0.0, wrap-ansi@^7.0.0:
29832+
version "7.0.0"
29833+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
29834+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
2983529835
dependencies:
2983629836
ansi-styles "^4.0.0"
2983729837
string-width "^4.1.0"
2983829838
strip-ansi "^6.0.0"
2983929839

29840-
wrap-ansi@^7.0.0:
29841-
version "7.0.0"
29842-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
29843-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
29840+
wrap-ansi@^6.0.1:
29841+
version "6.2.0"
29842+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
29843+
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==
2984429844
dependencies:
2984529845
ansi-styles "^4.0.0"
2984629846
string-width "^4.1.0"

0 commit comments

Comments
 (0)