@@ -72,7 +72,7 @@ function parseServerTimingTrace(serverTiming: readonly PerformanceServerTiming[]
7272
7373 const traceparentData = extractTraceparentData ( sentryTrace ) ;
7474 if ( ! traceparentData ?. traceId || ! traceparentData ?. parentSpanId ) {
75- DEBUG_BUILD && debug . warn ( '[Server-Timing] Invalid sentry-trace format:' , sentryTrace ) ;
75+ DEBUG_BUILD && debug . warn ( 'Invalid sentry-trace format:' , sentryTrace ) ;
7676 return null ;
7777 }
7878
@@ -117,17 +117,15 @@ function tryGetNavigationTraceContext(): NavigationTraceResult {
117117}
118118
119119/**
120- * Get trace context from the initial navigation (page load).
121- * Reads the Server-Timing header from the navigation performance entry.
122- * Results are cached after first successful retrieval.
120+ * Get trace context from Server-Timing header synchronously. Results are cached.
123121 */
124122export function getNavigationTraceContext ( ) : ServerTimingTraceContext | null {
125123 if ( navigationTraceCache !== undefined ) {
126124 return navigationTraceCache ;
127125 }
128126
129127 if ( ! isServerTimingSupported ( ) ) {
130- DEBUG_BUILD && debug . log ( '[Server-Timing] Server-Timing API not supported' ) ;
128+ DEBUG_BUILD && debug . log ( 'Server-Timing API not supported' ) ;
131129 navigationTraceCache = null ;
132130 return null ;
133131 }
@@ -147,10 +145,8 @@ export function getNavigationTraceContext(): ServerTimingTraceContext | null {
147145}
148146
149147/**
150- * Get trace context from navigation with retry mechanism.
151- * Useful during SDK init when browser may not have finished processing headers.
152- *
153- * @returns Cleanup function to cancel pending retries (e.g., on navigation)
148+ * Get trace context from Server-Timing header with retry mechanism for early SDK initialization.
149+ * Returns a cleanup function to cancel pending retries.
154150 */
155151export function getNavigationTraceContextAsync (
156152 callback : ( trace : ServerTimingTraceContext | null ) => void ,
@@ -167,7 +163,7 @@ export function getNavigationTraceContextAsync(
167163 }
168164
169165 if ( ! isServerTimingSupported ( ) ) {
170- DEBUG_BUILD && debug . log ( '[Server-Timing] Server-Timing API not supported' ) ;
166+ DEBUG_BUILD && debug . log ( 'Server-Timing API not supported' ) ;
171167 navigationTraceCache = null ;
172168 callback ( null ) ;
173169 return ( ) => {
@@ -187,21 +183,27 @@ export function getNavigationTraceContextAsync(
187183
188184 switch ( result . status ) {
189185 case 'unavailable' :
190- navigationTraceCache = null ;
191- callback ( null ) ;
186+ if ( ! state . cancelled ) {
187+ navigationTraceCache = null ;
188+ callback ( null ) ;
189+ }
192190 return ;
193191 case 'pending' :
194192 if ( attempts < maxAttempts ) {
195193 setTimeout ( tryGet , delayMs ) ;
196194 return ;
197195 }
198- DEBUG_BUILD && debug . warn ( '[Server-Timing] Max retry attempts reached, trace context unavailable' ) ;
199- navigationTraceCache = null ;
200- callback ( null ) ;
196+ DEBUG_BUILD && debug . warn ( 'Max retry attempts reached, trace context unavailable' ) ;
197+ if ( ! state . cancelled ) {
198+ navigationTraceCache = null ;
199+ callback ( null ) ;
200+ }
201201 return ;
202202 case 'available' :
203- navigationTraceCache = result . data ;
204- callback ( result . data ) ;
203+ if ( ! state . cancelled ) {
204+ navigationTraceCache = result . data ;
205+ callback ( result . data ) ;
206+ }
205207 }
206208 } ;
207209
@@ -213,8 +215,7 @@ export function getNavigationTraceContextAsync(
213215}
214216
215217/**
216- * Get trace context from meta tags.
217- * Looks for `<meta name="sentry-trace">` and `<meta name="baggage">` tags.
218+ * Get trace context from meta tags as a fallback for browsers without Server-Timing support.
218219 */
219220export function getMetaTagTraceContext ( ) : ServerTimingTraceContext | null {
220221 if ( typeof WINDOW === 'undefined' || ! WINDOW . document ) {
@@ -233,7 +234,7 @@ export function getMetaTagTraceContext(): ServerTimingTraceContext | null {
233234
234235 const traceparentData = extractTraceparentData ( sentryTrace ) ;
235236 if ( ! traceparentData ?. traceId || ! traceparentData ?. parentSpanId ) {
236- DEBUG_BUILD && debug . warn ( '[Server-Timing] Invalid sentry-trace format in meta tag:' , sentryTrace ) ;
237+ DEBUG_BUILD && debug . warn ( 'Invalid sentry-trace format in meta tag:' , sentryTrace ) ;
237238 return null ;
238239 }
239240
@@ -246,7 +247,10 @@ export function getMetaTagTraceContext(): ServerTimingTraceContext | null {
246247 }
247248}
248249
249- /** @internal */
250+ /**
251+ * Resets the navigation trace cache for fresh retrieval.
252+ * @internal
253+ */
250254export function clearNavigationTraceCache ( ) : void {
251255 navigationTraceCache = undefined ;
252256}
0 commit comments