-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Is there any global way to capture the name of called/executed functions? #57
Comments
Hi @helio-frota! 👋 If I understand correctly, you want to be able to emit the names and arguments of functions as they execute, without necessarily having to annotate them yourself? There isn't any built-in way to do this unfortunately, I am interested in trying to come up with a nice macro for annotating function calls so they produce useful flame-graph-like events though. Until then, I would probably use the extern crate emit;
extern crate emit_file;
extern crate emit_term;
use std::time::Duration;
#[emit::span("{fn_name}({#[emit::as_serde] blocks})", fn_name: "similar")]
fn similar(blocks: Vec<String>) -> Vec<(String, String, f64)> {
vec![]
}
fn main() {
let rt = emit::setup()
.emit_to(emit_term::stdout())
.and_emit_to(emit_file::set("./target/logs/log.txt").spawn().unwrap())
.init();
similar(vec![
"a".to_owned(),
"b".to_owned(),
"c".to_owned(),
]);
rt.blocking_flush(Duration::from_secs(5));
} That will produce output like this to the console: and like this to the rolling file: {"ts_start":"2024-06-14T22:25:29.198058000Z","ts":"2024-06-14T22:25:29.198731000Z","msg":"similar([\"a\", \"b\", \"c\"])","tpl":"{fn_name}({blocks})","blocks":["a","b","c"],"event_kind":"span","fn_name":"similar","span_id":"797146cc6879de98","span_name":"{fn_name}({blocks})","trace_id":"74d5777c80b9fcf64d85deb6efd6ce31"} With a nicer macro, I think we could get that annotation down to something like this: // Doesn't exist yet
#[emit_fn::span]
fn similar(blocks: Vec<String>) -> Vec<(String, String, f64)> {
vec![]
} Would that kind of approach work for you? |
yeah that's the idea
yes 🎉 This already would helps a lot as we could change all the pub functions with the following script for example
thanks for the response |
I found this crate cool thanks.
I have 2 use cases that helps me
a) to print the name of executed function
b) to send the function args content to log file with
in case of a) I need to add
#[emit::span("similar")]
before each function to grab the executed function namefor example:
So my question is related to this ^ situation ... I was reading the docs and the code but I have no idea if that is possible to do.
thanks.
The text was updated successfully, but these errors were encountered: