@@ -5,15 +5,15 @@ import {
55 getCurrentScope ,
66 htmlTreeAsString ,
77 SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME ,
8- SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT ,
9- SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE ,
108 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
119 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
10+ startInactiveSpan ,
1211} from '@sentry/core' ;
1312import { DEBUG_BUILD } from '../debug-build' ;
13+ import { WINDOW } from '../types' ;
1414import { addLcpInstrumentationHandler } from './instrument' ;
1515import type { WebVitalReportEvent } from './utils' ;
16- import { listenForWebVitalReportEvents , msToSec , startStandaloneWebVitalSpan , supportsWebVital } from './utils' ;
16+ import { listenForWebVitalReportEvents , msToSec , supportsWebVital } from './utils' ;
1717
1818/**
1919 * Starts tracking the Largest Contentful Paint on the current page and collects the value once
@@ -71,39 +71,29 @@ export function _sendStandaloneLcpSpan(
7171 'sentry.pageload.span_id' : pageloadSpanId ,
7272 // describes what triggered the web vital to be reported
7373 'sentry.report_event' : reportEvent ,
74- } ;
75-
76- if ( entry ) {
77- entry . element && ( attributes [ 'lcp.element' ] = htmlTreeAsString ( entry . element ) ) ;
78- entry . id && ( attributes [ 'lcp.id' ] = entry . id ) ;
7974
80- entry . url && ( attributes [ 'lcp.url' ] = entry . url ) ;
75+ // TODO: Relay currently expects 'lcp', but we should consider 'lcp.value'
76+ 'lcp' : lcpValue ,
77+ 'lcp.value' : lcpValue ,
8178
82- // loadTime is the time of LCP that's related to receiving the LCP element response..
83- entry . loadTime != null && ( attributes [ 'lcp.loadTime' ] = entry . loadTime ) ;
79+ 'lcp.element' : entry ?. element ? htmlTreeAsString ( entry . element ) : undefined ,
80+ 'lcp.id' : entry ?. id ,
81+ 'lcp.url' : entry ?. url ,
82+ 'lcp.loadTime' : entry ?. loadTime ,
83+ 'lcp.renderTime' : entry ?. renderTime ,
84+ 'lcp.size' : entry ?. size ,
8485
85- // renderTime is loadTime + rendering time
86- // it's 0 if the LCP element is loaded from a 3rd party origin that doesn't send the
87- // `Timing-Allow-Origin` header.
88- entry . renderTime != null && ( attributes [ 'lcp.renderTime' ] = entry . renderTime ) ;
86+ transaction : routeName ,
8987
90- entry . size != null && ( attributes [ 'lcp.size' ] = entry . size ) ;
91- }
88+ // Web vital score calculation relies on the user agent to account for different
89+ // browsers setting different thresholds for what is considered a good/meh/bad value.
90+ // For example: Chrome vs. Chrome Mobile
91+ 'user_agent.original' : WINDOW . navigator ?. userAgent ,
92+ } ;
9293
93- const span = startStandaloneWebVitalSpan ( {
94+ startInactiveSpan ( {
9495 name,
95- transaction : routeName ,
9696 attributes,
9797 startTime,
98- } ) ;
99-
100- if ( span ) {
101- span . addEvent ( 'lcp' , {
102- [ SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT ] : 'millisecond' ,
103- [ SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE ] : lcpValue ,
104- } ) ;
105-
106- // LCP is a point-in-time metric, so we end the span immediately
107- span . end ( startTime ) ;
108- }
98+ } ) ?. end ( startTime ) ;
10999}
0 commit comments