@@ -40,6 +40,14 @@ export const timeToDisplayIntegration = (): Integration => {
4040 return event ;
4141 }
4242
43+ // `trace_id` is a required field of a transaction's trace context and is
44+ // always present here alongside `rootSpanId`. Read it (instead of early
45+ // returning) so the TTID/TTFD spans inherit the transaction's trace and
46+ // nest correctly, and so we never skip the coordinator cleanup at the end
47+ // of `processEvent`. If it were ever absent, `createSpanJSON` keeps its
48+ // existing behavior of generating one.
49+ const traceId = event . contexts ?. trace ?. trace_id ;
50+
4351 const transactionStartTimestampSeconds = event . start_timestamp ;
4452 if ( ! transactionStartTimestampSeconds ) {
4553 // This should never happen
@@ -53,10 +61,17 @@ export const timeToDisplayIntegration = (): Integration => {
5361 const ttidSpan = await addTimeToInitialDisplay ( {
5462 event,
5563 rootSpanId,
64+ traceId,
5665 transactionStartTimestampSeconds,
5766 enableTimeToInitialDisplayForPreloadedRoutes,
5867 } ) ;
59- const ttfdSpan = await addTimeToFullDisplay ( { event, rootSpanId, transactionStartTimestampSeconds, ttidSpan } ) ;
68+ const ttfdSpan = await addTimeToFullDisplay ( {
69+ event,
70+ rootSpanId,
71+ traceId,
72+ transactionStartTimestampSeconds,
73+ ttidSpan,
74+ } ) ;
6075
6176 const ttidDurationMs =
6277 ttidSpan ?. start_timestamp && ttidSpan ?. timestamp
@@ -109,11 +124,13 @@ export const timeToDisplayIntegration = (): Integration => {
109124async function addTimeToInitialDisplay ( {
110125 event,
111126 rootSpanId,
127+ traceId,
112128 transactionStartTimestampSeconds,
113129 enableTimeToInitialDisplayForPreloadedRoutes,
114130} : {
115131 event : Event ;
116132 rootSpanId : string ;
133+ traceId : string | undefined ;
117134 transactionStartTimestampSeconds : number ;
118135 enableTimeToInitialDisplayForPreloadedRoutes : boolean ;
119136} ) : Promise < SpanJSON | undefined > {
@@ -133,6 +150,7 @@ async function addTimeToInitialDisplay({
133150 return addAutomaticTimeToInitialDisplay ( {
134151 event,
135152 rootSpanId,
153+ traceId,
136154 transactionStartTimestampSeconds,
137155 enableTimeToInitialDisplayForPreloadedRoutes,
138156 } ) ;
@@ -156,6 +174,7 @@ async function addTimeToInitialDisplay({
156174 timestamp : ttidEndTimestampSeconds ,
157175 origin : SPAN_ORIGIN_MANUAL_UI_TIME_TO_DISPLAY ,
158176 parent_span_id : rootSpanId ,
177+ trace_id : traceId ,
159178 data : {
160179 [ SPAN_THREAD_NAME ] : SPAN_THREAD_NAME_JAVASCRIPT ,
161180 } ,
@@ -168,11 +187,13 @@ async function addTimeToInitialDisplay({
168187async function addAutomaticTimeToInitialDisplay ( {
169188 event,
170189 rootSpanId,
190+ traceId,
171191 transactionStartTimestampSeconds,
172192 enableTimeToInitialDisplayForPreloadedRoutes,
173193} : {
174194 event : Event ;
175195 rootSpanId : string ;
196+ traceId : string | undefined ;
176197 transactionStartTimestampSeconds : number ;
177198 enableTimeToInitialDisplayForPreloadedRoutes : boolean ;
178199} ) : Promise < SpanJSON | undefined > {
@@ -205,6 +226,7 @@ async function addAutomaticTimeToInitialDisplay({
205226 timestamp : ttidTimestampSeconds ,
206227 origin : SPAN_ORIGIN_AUTO_UI_TIME_TO_DISPLAY ,
207228 parent_span_id : rootSpanId ,
229+ trace_id : traceId ,
208230 data : {
209231 [ SPAN_THREAD_NAME ] : SPAN_THREAD_NAME_JAVASCRIPT ,
210232 } ,
@@ -217,11 +239,13 @@ async function addAutomaticTimeToInitialDisplay({
217239async function addTimeToFullDisplay ( {
218240 event,
219241 rootSpanId,
242+ traceId,
220243 transactionStartTimestampSeconds,
221244 ttidSpan,
222245} : {
223246 event : Event ;
224247 rootSpanId : string ;
248+ traceId : string | undefined ;
225249 transactionStartTimestampSeconds : number ;
226250 ttidSpan : SpanJSON | undefined ;
227251} ) : Promise < SpanJSON | undefined > {
@@ -271,6 +295,7 @@ async function addTimeToFullDisplay({
271295 timestamp : ttfdAdjustedEndTimestampSeconds ,
272296 origin : SPAN_ORIGIN_MANUAL_UI_TIME_TO_DISPLAY ,
273297 parent_span_id : rootSpanId ,
298+ trace_id : traceId ,
274299 data : {
275300 [ SPAN_THREAD_NAME ] : SPAN_THREAD_NAME_JAVASCRIPT ,
276301 } ,
0 commit comments