Skip to content
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

Add an instrument attribute for tracing function execution #141

Closed
KodrAus opened this issue Oct 19, 2024 · 1 comment
Closed

Add an instrument attribute for tracing function execution #141

KodrAus opened this issue Oct 19, 2024 · 1 comment

Comments

@KodrAus
Copy link
Contributor

KodrAus commented Oct 19, 2024

For #57

This is something that would also help when using emit in tests. It would be nice to have a span attribute that was tailored for tracing function execution:

fn test_setup() {
    let _ = emit::setup().emit_to(emit_term::stdout()).init();
}

#[emit::span_fn(setup: test_setup)]
#[test]
fn my_test() {
    ..
}

The setup parameter is one we could add to emit::span that evaluates an expression before it does the internal span setup so you've got a chance to initialize emit. Then span_fn could expand to something like:

#[emit::span(setup: test_setup, "my_test()")]
#[test]
fn my_test() {

}

If the function had arguments, those could be listed in a props collection to be included:

#[emit::span_fn(args: { #[emit::as_debug] a })]
fn some_fn(a: u32, b: Uncaptured) {
    ..
}

would expand to:

#[emit::span("some_fn({#[emit::as_debug] a})")]
fn some_fn(a: u32, b: Uncaptured) {
    ..
}

It might also be nice to include some unique identifier, like a hash of the full function name, on the emitted events so you can use them to build an aggregated flamegraph.

@KodrAus KodrAus changed the title Add an instrument method for tracing function execution Add an instrument attribute for tracing function execution Oct 19, 2024
@KodrAus
Copy link
Contributor Author

KodrAus commented Jan 8, 2025

This isn't something we'd need direct support for in emit, but could make a good external library.

@KodrAus KodrAus closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant