diff --git a/Cargo.lock b/Cargo.lock index 947a12c92b..85936593ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5357,7 +5357,6 @@ dependencies = [ "lgn-tracing-transit", "log", "memoffset", - "pin-project-lite", "raw-cpuid", "thiserror", "thread-id", @@ -8573,15 +8572,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" -[[package]] -name = "test-async-span-fn" -version = "0.1.0" -dependencies = [ - "lgn-telemetry-sink", - "lgn-tracing", - "tokio", -] - [[package]] name = "testcontainers" version = "0.12.0" diff --git a/crates/lgn-tracing/Cargo.toml b/crates/lgn-tracing/Cargo.toml index 3bca3e418c..40d071c990 100644 --- a/crates/lgn-tracing/Cargo.toml +++ b/crates/lgn-tracing/Cargo.toml @@ -20,7 +20,6 @@ chrono = "0.4" memoffset = "0.6" thread-id = "4.0" lazy_static = "1.4" -pin-project-lite = "0.2.9" [dev-dependencies] criterion = "0.3" diff --git a/crates/lgn-tracing/proc-macros/src/lib.rs b/crates/lgn-tracing/proc-macros/src/lib.rs index 5f34d9422a..2f96f11e60 100644 --- a/crates/lgn-tracing/proc-macros/src/lib.rs +++ b/crates/lgn-tracing/proc-macros/src/lib.rs @@ -40,56 +40,27 @@ pub fn span_fn( args: proc_macro::TokenStream, input: proc_macro::TokenStream, ) -> proc_macro::TokenStream { - let args = parse_macro_input!(args as TraceArgs); let mut function = parse_macro_input!(input as ItemFn); - let function_name = args - .alternative_name - .map_or(function.sig.ident.to_string(), |n| n.to_string()); - - if function.sig.asyncness.is_none() { - function.block.stmts.insert(0, parse_quote! { - lgn_tracing::span_scope!(_METADATA_FUNC, concat!(module_path!(), "::", #function_name)); - }); - + if function.sig.asyncness.is_some() { + // NOOP For now return proc_macro::TokenStream::from(quote! { #function }); - } + }; - let stmts = function.block.stmts; + let args = parse_macro_input!(args as TraceArgs); - function.block.stmts = vec![ - parse_quote! { - static _METADATA_FUNC: lgn_tracing::spans::SpanMetadata = lgn_tracing::spans::SpanMetadata { - name: concat!(module_path!(), "::", #function_name), - location: lgn_tracing::spans::SpanLocation { - lod: lgn_tracing::Verbosity::Max, - target: module_path!(), - module_path: module_path!(), - file: file!(), - line: line!() - } - }; - }, - parse_quote! { - lgn_tracing::dispatch::on_begin_scope(&_METADATA_FUNC); - }, - parse_quote! { - let __lgn_tracing_future = async move { - #(#stmts)* - }; - }, - parse_quote! { - let __lgn_tracing_output = lgn_tracing::spans::Instrumentation::new(__lgn_tracing_future, &_METADATA_FUNC).await; - }, - parse_quote! { - lgn_tracing::dispatch::on_end_scope(&_METADATA_FUNC); - }, + let function_name = args + .alternative_name + .map_or(function.sig.ident.to_string(), |n| n.to_string()); + + function.block.stmts.insert( + 0, parse_quote! { - return __lgn_tracing_output; + lgn_tracing::span_scope!(_METADATA_FUNC, concat!(module_path!(), "::", #function_name)); }, - ]; + ); proc_macro::TokenStream::from(quote! { #function diff --git a/crates/lgn-tracing/src/spans/instrument.rs b/crates/lgn-tracing/src/spans/instrument.rs deleted file mode 100644 index 26adade530..0000000000 --- a/crates/lgn-tracing/src/spans/instrument.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Async instrumentation - -#![allow(clippy::use_self)] - -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -use pin_project_lite::pin_project; - -use crate::dispatch::{on_begin_scope, on_end_scope}; - -use super::SpanMetadata; - -pin_project! { - pub struct Instrumentation { - #[pin] - inner: T, - span: &'static SpanMetadata, - // An [`Instrumentation`] is idle when it has been polled at least once - // and that the inner Future returned `Poll::Pending`. - // As soon as the inner Future returns `Poll::Ready` this attribute is set to `false`. - is_idle: bool - } -} - -impl Instrumentation { - pub fn new(inner: T, span: &'static SpanMetadata) -> Self { - Instrumentation { - inner, - span, - is_idle: false, - } - } -} - -impl Future for Instrumentation { - type Output = T::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - - let output = this.inner.poll(cx); - - if output.is_pending() && !*this.is_idle { - on_end_scope(this.span); - - *this.is_idle = true; - } - - if output.is_ready() { - on_begin_scope(this.span); - - *this.is_idle = false; - } - - output - } -} diff --git a/crates/lgn-tracing/src/spans/mod.rs b/crates/lgn-tracing/src/spans/mod.rs index 9b9531ae4e..8a40a1e748 100644 --- a/crates/lgn-tracing/src/spans/mod.rs +++ b/crates/lgn-tracing/src/spans/mod.rs @@ -3,7 +3,5 @@ pub use block::*; mod events; pub use events::*; -mod instrument; -pub use instrument::*; // todo: implement non thread based perf spans for other systems to be used diff --git a/tests/async-span-fn/Cargo.toml b/tests/async-span-fn/Cargo.toml deleted file mode 100644 index d76562c623..0000000000 --- a/tests/async-span-fn/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "test-async-span-fn" -version = "0.1.0" -edition = "2021" -homepage = "https://legionengine.com" -repository = "https://github.com/legion-labs/legion" -license = "MIT OR Apache-2.0" - -[dependencies] -lgn-telemetry-sink = { path = "../../crates/lgn-telemetry-sink", version = "0.1.0" } -lgn-tracing = { path = "../../crates/lgn-tracing", version = "0.1.0" } -tokio = { version = "1", features = ["full"] } diff --git a/tests/async-span-fn/src/main.rs b/tests/async-span-fn/src/main.rs deleted file mode 100644 index d4f13da682..0000000000 --- a/tests/async-span-fn/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -//! Dumb binary to test async span fn - -#![allow(clippy::never_loop)] - -use std::time::Duration; - -use lgn_telemetry_sink::TelemetryGuard; -use lgn_tracing::{info, span_fn}; -use tokio::time::sleep; - -#[span_fn] -async fn empty_return() { - sleep(Duration::from_millis(1)).await; -} - -#[span_fn] -async fn iteration_with_cond() { - let a = 3; - - loop { - if a == 3 { - println!("a was 3"); - sleep(Duration::from_millis(1)).await; - } - - break; - } - - info!("inside my_function!"); -} - -#[span_fn] -async fn delayed_value() -> String { - sleep(Duration::from_millis(1)).await; - - "After".into() -} - -#[span_fn] -fn consume_delayed_value(_: String) { - println!("Consumed a delayed value"); -} - -#[span_fn] -async fn delayed() { - println!("Before"); - - sleep(Duration::from_millis(1)).await; - - println!("Second"); - - let msg = delayed_value().await; - - println!("{}", msg); - - consume_delayed_value(delayed_value().await); -} - -#[tokio::main] -async fn main() { - let _telemetry_guard = TelemetryGuard::default().unwrap(); - - delayed().await; - - iteration_with_cond().await; - - empty_return().await; -}