@@ -31,9 +31,7 @@ import {
3131 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
3232 SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
3333 setHttpStatus ,
34- spanToBaggageHeader ,
3534 spanToJSON ,
36- spanToTraceHeader ,
3735 startSpan ,
3836 winterCGHeadersToDict ,
3937 winterCGRequestToRequestData ,
@@ -105,34 +103,34 @@ export function wrapHandleErrorWithSentry(
105103}
106104
107105/**
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 .
106+ * Get trace context for injection into loader response data (for meta tags) .
107+ * Returns empty object when Server-Timing headers are available, as they take priority.
108+ * Only provides trace data for meta tags as a fallback mechanism .
111109 */
112110function getTraceAndBaggage ( ) : {
113111 sentryTrace ?: string ;
114112 sentryBaggage ?: string ;
115113} {
114+ // Server-Timing headers take priority over meta tags.
115+ // When in Node.js or Cloudflare environments with an active span,
116+ // Server-Timing headers will be injected, so skip meta tag data.
116117 if ( isNodeEnv ( ) || isCloudflareEnv ( ) ) {
117118 const activeSpan = getActiveSpan ( ) ;
118119 if ( activeSpan ) {
119- const sentryTrace = spanToTraceHeader ( activeSpan ) ;
120- if ( sentryTrace ) {
121- return {
122- sentryTrace,
123- sentryBaggage : spanToBaggageHeader ( activeSpan ) ,
124- } ;
125- }
120+ // Server-Timing header will be available, skip meta tag injection
121+ DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Skipping meta tag injection - Server-Timing header will be used' ) ;
122+ return { } ;
126123 }
127124
125+ // No active span - fall back to meta tags via propagation context
128126 const scope = getCurrentScope ( ) ;
129127 const propagationContext = scope . getPropagationContext ( ) ;
130128 const traceData = getTraceData ( ) ;
131129 const spanId = propagationContext . propagationSpanId ?? propagationContext . parentSpanId ;
132130
133131 if ( propagationContext . traceId && spanId ) {
134132 const fallbackTrace = generateSentryTraceHeader ( propagationContext . traceId , spanId , propagationContext . sampled ) ;
135- DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Falling back to propagation context:' , fallbackTrace ) ;
133+ DEBUG_BUILD && debug . log ( '[getTraceAndBaggage] Using meta tags fallback - no active span for Server-Timing' ) ;
136134
137135 return {
138136 sentryTrace : fallbackTrace ,
0 commit comments