@@ -105,34 +105,34 @@ export function wrapHandleErrorWithSentry(
105105}
106106
107107/**
108- * Get trace context for injection into loader response data.
109- * Prioritizes active span context to ensure client pageload continues from the loader span,
110- * not the http.server span, enabling proper trace continuity via Server-Timing headers .
108+ * Get trace context for injection into loader response data (for meta tags) .
109+ * Returns empty object when Server-Timing headers are available, as they take priority.
110+ * Only provides trace data for meta tags as a fallback mechanism .
111111 */
112112function getTraceAndBaggage ( ) : {
113113 sentryTrace ?: string ;
114114 sentryBaggage ?: string ;
115115} {
116+ // Server-Timing headers take priority over meta tags.
117+ // When in Node.js or Cloudflare environments with an active span,
118+ // Server-Timing headers will be injected, so skip meta tag data.
116119 if ( isNodeEnv ( ) || isCloudflareEnv ( ) ) {
117120 const activeSpan = getActiveSpan ( ) ;
118121 if ( activeSpan ) {
119- const sentryTrace = spanToTraceHeader ( activeSpan ) ;
120- if ( sentryTrace ) {
121- return {
122- sentryTrace,
123- sentryBaggage : spanToBaggageHeader ( activeSpan ) ,
124- } ;
125- }
122+ // Server-Timing header will be available, skip meta tag injection
123+ DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Skipping meta tag injection - Server-Timing header will be used' ) ;
124+ return { } ;
126125 }
127126
127+ // No active span - fall back to meta tags via propagation context
128128 const scope = getCurrentScope ( ) ;
129129 const propagationContext = scope . getPropagationContext ( ) ;
130130 const traceData = getTraceData ( ) ;
131131 const spanId = propagationContext . propagationSpanId ?? propagationContext . parentSpanId ;
132132
133133 if ( propagationContext . traceId && spanId ) {
134134 const fallbackTrace = generateSentryTraceHeader ( propagationContext . traceId , spanId , propagationContext . sampled ) ;
135- DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Falling back to propagation context:' , fallbackTrace ) ;
135+ DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Using meta tags fallback - no active span for Server-Timing' ) ;
136136
137137 return {
138138 sentryTrace : fallbackTrace ,
0 commit comments