Skip to content

Commit 432acb3

Browse files
authored
feat(debug): add call_id to load and transform events (#4296)
<!-- Thank you for contributing! --> ### Description <!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
1 parent f675391 commit 432acb3

File tree

9 files changed

+61
-25
lines changed

9 files changed

+61
-25
lines changed

crates/rolldown_debug_action/src/definitions/hook_load_call_end.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pub struct HookLoadCallEnd {
88
pub plugin_name: String,
99
/// The index of the plugin in the plugin list. It's unique to each plugin.
1010
pub plugin_index: u32,
11+
pub call_id: &'static str,
1112
}

crates/rolldown_debug_action/src/definitions/hook_load_call_start.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ pub struct HookLoadCallStart {
77
pub plugin_name: String,
88
/// The index of the plugin in the plugin list. It's unique to each plugin.
99
pub plugin_index: u32,
10+
pub call_id: &'static str,
1011
}

crates/rolldown_debug_action/src/definitions/hook_transform_call_end.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pub struct HookTransformCallEnd {
88
pub plugin_name: String,
99
/// The index of the plugin in the plugin list. It's unique to each plugin.
1010
pub plugin_index: u32,
11+
pub call_id: String,
1112
}

crates/rolldown_debug_action/src/definitions/hook_transform_call_start.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pub struct HookTransformCallStart {
88
pub plugin_name: String,
99
/// The index of the plugin in the plugin list. It's unique to each plugin.
1010
pub plugin_index: u32,
11+
pub call_id: String,
1112
}

crates/rolldown_plugin/src/plugin_driver/build_hooks.rs

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{borrow::Cow, sync::Arc};
22

33
use crate::{
44
HookBuildEndArgs, HookLoadArgs, HookLoadReturn, HookNoopReturn, HookResolveIdArgs,
@@ -215,33 +215,48 @@ impl PluginDriver {
215215
if !self.plugin_usage_vec[plugin_idx].contains(HookUsage::Load) {
216216
continue;
217217
}
218-
trace_action!(action::HookLoadCallStart {
219-
action: "HookLoadCallStart",
220-
module_id: args.id.to_string(),
221-
plugin_name: plugin.call_name().to_string(),
222-
plugin_index: plugin_idx.raw()
223-
});
224-
if let Some(r) = plugin
225-
.call_load(ctx, args)
226-
.instrument(debug_span!("load_hook", plugin_name = plugin.call_name().as_ref()))
227-
.await?
228-
{
229-
trace_action!(action::HookLoadCallEnd {
230-
action: "HookLoadCallEnd",
218+
let ret = async {
219+
trace_action!(action::HookLoadCallStart {
220+
action: "HookLoadCallStart",
231221
module_id: args.id.to_string(),
232-
source: Some(r.code.to_string()),
233222
plugin_name: plugin.call_name().to_string(),
234-
plugin_index: plugin_idx.raw()
223+
plugin_index: plugin_idx.raw(),
224+
call_id: "${call_id}",
235225
});
236-
return Ok(Some(r));
226+
if let Some(r) = plugin
227+
.call_load(ctx, args)
228+
.instrument(debug_span!("load_hook", plugin_name = plugin.call_name().as_ref()))
229+
.await?
230+
{
231+
trace_action!(action::HookLoadCallEnd {
232+
action: "HookLoadCallEnd",
233+
module_id: args.id.to_string(),
234+
source: Some(r.code.to_string()),
235+
plugin_name: plugin.call_name().to_string(),
236+
plugin_index: plugin_idx.raw(),
237+
call_id: "${call_id}",
238+
});
239+
anyhow::Ok(Some(r))
240+
} else {
241+
trace_action!(action::HookLoadCallEnd {
242+
action: "HookLoadCallEnd",
243+
module_id: args.id.to_string(),
244+
source: None,
245+
plugin_name: plugin.call_name().to_string(),
246+
plugin_index: plugin_idx.raw(),
247+
call_id: "${call_id}",
248+
});
249+
Ok(None)
250+
}
251+
}
252+
.instrument(tracing::trace_span!(
253+
"HookLoadCall",
254+
CONTEXT_call_id = format!("load_{}", rolldown_utils::time::current_utc_timestamp_ms())
255+
))
256+
.await?;
257+
if ret.is_some() {
258+
return Ok(ret);
237259
}
238-
trace_action!(action::HookLoadCallEnd {
239-
action: "HookLoadCallEnd",
240-
module_id: args.id.to_string(),
241-
source: None,
242-
plugin_name: plugin.call_name().to_string(),
243-
plugin_index: plugin_idx.raw()
244-
});
245260
}
246261
Ok(None)
247262
}
@@ -264,12 +279,23 @@ impl PluginDriver {
264279
if !self.plugin_usage_vec[plugin_idx].contains(HookUsage::Transform) {
265280
continue;
266281
}
282+
let call_id = if tracing::enabled!(tracing::Level::TRACE) {
283+
Cow::Owned(format!(
284+
"transform_{}_{}",
285+
plugin_idx.raw(),
286+
rolldown_utils::time::current_utc_timestamp_ms()
287+
))
288+
} else {
289+
Cow::Borrowed("")
290+
};
291+
267292
trace_action!(action::HookTransformCallStart {
268293
action: "HookTransformCallStart",
269294
module_id: id.to_string(),
270295
source: code.clone(),
271296
plugin_name: plugin.call_name().to_string(),
272-
plugin_index: plugin_idx.raw()
297+
plugin_index: plugin_idx.raw(),
298+
call_id: call_id.to_string(),
273299
});
274300
if let Some(r) = plugin
275301
.call_transform(
@@ -300,6 +326,7 @@ impl PluginDriver {
300326
transformed_source: Some(code.to_string()),
301327
plugin_name: plugin.call_name().to_string(),
302328
plugin_index: plugin_idx.raw(),
329+
call_id: call_id.to_string()
303330
});
304331
}
305332
if let Some(ty) = r.module_type {
@@ -312,6 +339,7 @@ impl PluginDriver {
312339
transformed_source: Some(code.to_string()),
313340
plugin_name: plugin.call_name().to_string(),
314341
plugin_index: plugin_idx.raw(),
342+
call_id: call_id.to_string()
315343
});
316344
}
317345
}

packages/debug/src/generated/HookLoadCallEnd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type HookLoadCallEnd = {
99
* The index of the plugin in the plugin list. It's unique to each plugin.
1010
*/
1111
plugin_index: number;
12+
call_id: string;
1213
};

packages/debug/src/generated/HookLoadCallStart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export type HookLoadCallStart = {
88
* The index of the plugin in the plugin list. It's unique to each plugin.
99
*/
1010
plugin_index: number;
11+
call_id: string;
1112
};

packages/debug/src/generated/HookTransformCallEnd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type HookTransformCallEnd = {
99
* The index of the plugin in the plugin list. It's unique to each plugin.
1010
*/
1111
plugin_index: number;
12+
call_id: string;
1213
};

packages/debug/src/generated/HookTransformCallStart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type HookTransformCallStart = {
99
* The index of the plugin in the plugin list. It's unique to each plugin.
1010
*/
1111
plugin_index: number;
12+
call_id: string;
1213
};

0 commit comments

Comments
 (0)