Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ impl Instrumentation {
self.has_injected = false;
}

fn new_fn(&self, body: BlockStmt, params: Vec<Pat>) -> ArrowExpr {
ArrowExpr {
params,
body: Box::new(body.into()),
is_async: self.config.function_query.kind().is_async(),
is_generator: false,
type_params: None,
return_type: None,
span: Span::default(),
ctxt: SyntaxContext::empty(),
}
}

fn create_tracing_channel(&self) -> Stmt {
let ch_str = ident!(format!("tr_ch_apm${}", self.config.get_identifier_name()));
let channel_string = Expr::Lit(Lit::Str(Str {
Expand Down Expand Up @@ -112,7 +99,7 @@ impl Instrumentation {

let original_params: Vec<Pat> = params.iter().map(|p| p.pat.clone()).collect();

let wrapped_fn = self.new_fn(original_body, original_params);
let wrapped_fn = new_fn(original_body, original_params);

let traced_body = BlockStmt {
span: Span::default(),
Expand All @@ -123,7 +110,7 @@ impl Instrumentation {
],
};

let traced_fn = self.new_fn(traced_body, vec![]);
let traced_fn = new_fn(traced_body, vec![]);

let id_name = self.config.get_identifier_name();
let ch_ident = ident!(format!("tr_ch_apm${}", &id_name));
Expand Down Expand Up @@ -398,3 +385,21 @@ pub fn get_script_start_index(script: &Script) -> usize {
}
0
}

#[must_use]
pub fn new_fn(body: BlockStmt, params: Vec<Pat>) -> ArrowExpr {
ArrowExpr {
params,
body: Box::new(body.into()),
// if we set this to `true` and it's an async function,
// it will wrap the original promise in a new native one
// which may not be semantically correct in cases where custom
// promises are returned
is_async: false,
is_generator: false,
type_params: None,
return_type: None,
span: Span::default(),
ctxt: SyntaxContext::empty(),
}
}