tracing_attributes_http/
lib.rs

1//! Procedural macro attributes for instrumenting functions with [`tracing`], in
2//! HTTP use cases, following the [`opentelemetry`] conventions.
3//!
4
5use proc_macro::TokenStream;
6use proc_macro_error::proc_macro_error;
7
8mod server_send;
9mod utility;
10
11/// Add tracing instrumentation attribute: Server-Send
12///
13/// # Example
14///
15/// ```
16/// use tracing_attributes_http::*;
17///
18/// #[server_send(level = tracing::Level::TRACE, name = "Server::encode", skip = [dst, msg])
19/// fn encode(mut msg: Encode<'_, Self::Outgoing>, dst: &mut Vec<u8>) -> crate::Result<Encoder> {
20///     ...
21/// }
22/// ```
23
24#[proc_macro_attribute]
25#[proc_macro_error]
26pub fn server_send(metadata: TokenStream, item: TokenStream) -> TokenStream {
27    // Parse the list of arguments.
28    let meta = metadata.clone();
29    let meta_args = syn::parse_macro_input!(meta as crate::server_send::parse::Args);
30
31    let ast = server_send::parse(metadata.into(), item.into());
32    let model = server_send::analyze(ast, meta_args);
33    let ir = server_send::lower(model);
34    let rust = server_send::codegen(ir);
35    rust.into()
36}