Repository: vercel/next.js
Pull request: Turbopack: follow tracing spans through aggregation update queue

### What?

follow spans through the aggregation update queue

Changed files:
filename: turbopack/crates/turbo-tasks-backend/Cargo.toml
patch: @@ -20,11 +20,12 @@ verify_serialization = []
 verify_aggregation_graph = []
 verify_immutable = []
 verify_determinism = []
-trace_aggregation_update = []
+trace_aggregation_update_queue = []
+trace_aggregation_update = ["trace_aggregation_update_queue"]
 trace_leaf_distance_update = []
-trace_find_and_schedule = []
+trace_find_and_schedule = ["trace_aggregation_update_queue"]
 trace_task_completion = []
-trace_task_dirty = []
+trace_task_dirty = ["trace_aggregation_update_queue"]
 trace_task_output_dependencies = []
 trace_task_details = []
 lmdb = ["dep:lmdb-rkv"]

filename: turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs
patch: @@ -15,6 +15,8 @@ use indexmap::map::Entry;
 use ringmap::RingSet;
 use rustc_hash::{FxBuildHasher, FxHashMap};
 use smallvec::{SmallVec, smallvec};
+#[cfg(feature = "trace_aggregation_update_queue")]
+use tracing::span::Span;
 #[cfg(any(
     feature = "trace_aggregation_update",
     feature = "trace_find_and_schedule"
@@ -683,41 +685,41 @@ impl AggregatedDataUpdate {
 struct AggregationNumberUpdate {
     base_aggregation_number: u32,
     distance: Option<NonZeroU32>,
-    #[cfg(feature = "trace_aggregation_update")]
-    #[bincode(skip, default)]
+    #[cfg(feature = "trace_aggregation_update_queue")]
+    #[bincode(skip)]
     span: Option<Span>,
 }
 
 /// An aggregated data update job that is enqueued. See `AggregatedDataUpdate`.
 #[derive(Encode, Decode, Clone)]
 struct AggregationUpdateJobItem {
     job: AggregationUpdateJob,
-    #[cfg(feature = "trace_aggregation_update")]
-    #[bincode(skip, default)]
+    #[cfg(feature = "trace_aggregation_update_queue")]
+    #[bincode(skip)]
     span: Option<Span>,
 }
 
 impl AggregationUpdateJobItem {
     fn new(job: AggregationUpdateJob) -> Self {
         Self {
             job,
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             span: Some(Span::current()),
         }
     }
 
     fn entered(self) -> AggregationUpdateJobGuard {
         AggregationUpdateJobGuard {
             job: self.job,
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             _guard: self.span.map(|s| s.entered()),
         }
     }
 }
 
 struct AggregationUpdateJobGuard {
     job: AggregationUpdateJob,
-    #[cfg(feature = "trace_aggregation_update")]
+    #[cfg(feature = "trace_aggregation_update_queue")]
     _guard: Option<tracing::span::EnteredSpan>,
 }
 
@@ -726,8 +728,8 @@ struct AggregationUpdateJobGuard {
 struct BalanceJob {
     upper_id: TaskId,
     task_id: TaskId,
-    #[cfg(feature = "trace_aggregation_update")]
-    #[bincode(skip, default)]
+    #[cfg(feature = "trace_aggregation_update_queue")]
+    #[bincode(skip)]
     span: Option<Span>,
 }
 
@@ -736,7 +738,7 @@ impl BalanceJob {
         Self {
             upper_id: upper,
             task_id: task,
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             span: Some(Span::current()),
         }
     }
@@ -761,16 +763,16 @@ impl Eq for BalanceJob {}
 #[derive(Encode, Decode, Clone)]
 struct OptimizeJob {
     task_id: TaskId,
-    #[cfg(feature = "trace_aggregation_update")]
-    #[bincode(skip, default)]
+    #[cfg(feature = "trace_aggregation_update_queue")]
+    #[bincode(skip)]
     span: Option<Span>,
 }
 
 impl OptimizeJob {
     fn new(task: TaskId) -> Self {
         Self {
             task_id: task,
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             span: Some(Span::current()),
         }
     }
@@ -795,7 +797,7 @@ impl Eq for OptimizeJob {}
 struct FindAndScheduleJob {
     task_id: TaskId,
     #[cfg(feature = "trace_find_and_schedule")]
-    #[bincode(skip, default)]
+    #[bincode(skip)]
     span: Option<Span>,
 }
 
@@ -846,7 +848,7 @@ mod encode_jobs {
                 | AggregationUpdateJob::DecreaseActiveCounts { .. } => {
                     AggregationUpdateJobItem {
                         job: AggregationUpdateJob::Noop,
-                        #[cfg(feature = "trace_aggregation_update")]
+                        #[cfg(feature = "trace_aggregation_update_queue")]
                         span: None,
                     }
                     .encode(encoder)?;
@@ -966,7 +968,7 @@ impl AggregationUpdateQueue {
                         entry.insert(AggregationNumberUpdate {
                             base_aggregation_number,
                             distance,
-                            #[cfg(feature = "trace_aggregation_update")]
+                            #[cfg(feature = "trace_aggregation_update_queue")]
                             span: Some(Span::current()),
                         });
                     }
@@ -1215,19 +1217,19 @@ impl AggregationUpdateQueue {
                     AggregationNumberUpdate {
                         base_aggregation_number,
                         distance,
-                        #[cfg(feature = "trace_aggregation_update")]
+                        #[cfg(feature = "trace_aggregation_update_queue")]
                         span,
                     },
                 )) = self.aggregation_number_updates.pop()
                 {
-                    #[cfg(feature = "trace_aggregation_update")]
+                    #[cfg(feature = "trace_aggregation_update_queue")]
                     let _guard = span.map(|s| s.entered());
                     self.done_aggregation_number_updates.insert(
                         task_id,
                         AggregationNumberUpdate {
                             base_aggregation_number,
                             distance,
-                            #[cfg(feature = "trace_aggregation_update")]
+                            #[cfg(feature = "trace_aggregation_update_queue")]
                             span: None,
                         },
                     );
@@ -1244,11 +1246,11 @@ impl AggregationUpdateQueue {
                 if let Some(BalanceJob {
                     upper_id: upper,
                     task_id: task,
-                    #[cfg(feature = "trace_aggregation_update")]
+                    #[cfg(feature = "trace_aggregation_update_queue")]
                     span,
                 }) = self.balance_queue.pop_front()
                 {
-                    #[cfg(feature = "trace_aggregation_update")]
+                    #[cfg(feature = "trace_aggregation_update_queue")]
                     let _guard = span.map(|s| s.entered());
                     self.balance_edge(ctx, upper, task);
                     remaining -= 1;
@@ -1259,14 +1261,14 @@ impl AggregationUpdateQueue {
             false
         } else if let Some(OptimizeJob {
             task_id,
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             span,
         }) = self.optimize_queue.pop_front()
         {
             // Note: We must process one optimization completely before starting with the next one.
             // Otherwise this could lead to optimizing every node of a subgraph of inner nodes, as
             // all have the same upper count. Optimizing the root first
-            #[cfg(feature = "trace_aggregation_update")]
+            #[cfg(feature = "trace_aggregation_update_queue")]
             let _guard = span.map(|s| s.entered());
             self.optimize_task(ctx, task_id);
             false

filename: turbopack/crates/turbo-tasks-backend/src/backend/operation/leaf_distance_update.rs
patch: @@ -35,7 +35,7 @@ struct LeafDistanceUpdate {
     dependencies_max_distance_in_buffer: u32,
     done: bool,
     #[cfg(feature = "trace_leaf_distance_update")]
-    #[bincode(skip, default)]
+    #[bincode(skip)]
     span: Option<Span>,
 }