diff --git a/crates/common/src/tracing.rs b/crates/common/src/tracing.rs index f2005baa..123be5f4 100644 --- a/crates/common/src/tracing.rs +++ b/crates/common/src/tracing.rs @@ -266,6 +266,13 @@ mod tracing_on { ) }; } + + #[macro_export] + macro_rules! run_instrumented { + ($name:ident, $code:block) => { + $crate::instrument!($name, async move { $code }).await + }; + } } #[cfg(feature = "tracy-tracing")] pub use tracy_client; @@ -278,43 +285,9 @@ pub use self::tracing_on::{ #[cfg(not(feature = "tracy-tracing"))] mod tracing_off { - use std::{ - ffi::CStr, - future::Future, - pin::Pin, - task::{ - Context, - Poll, - }, - }; - - use pin_project::pin_project; - pub fn initialize() {} - #[pin_project] - pub struct InstrumentedFuture { - #[pin] - inner: F, - } - pub struct NoopLocation; - - impl InstrumentedFuture { - pub fn new(inner: F, _name: &'static CStr, _loc: &'static NoopLocation) -> Self { - Self { inner } - } - } - - impl Future for InstrumentedFuture { - type Output = F::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - this.inner.poll(cx) - } - } - pub struct NoopSpan; #[macro_export] @@ -341,12 +314,18 @@ mod tracing_off { $future }; } + + #[macro_export] + macro_rules! run_instrumented { + ($name:ident, $code:block) => { + $code + }; + } } #[cfg(not(feature = "tracy-tracing"))] pub use self::tracing_off::{ initialize, - InstrumentedFuture, NoopLocation, NoopSpan, }; diff --git a/crates/convex_macro/src/lib.rs b/crates/convex_macro/src/lib.rs index cf581a85..a4f025e9 100644 --- a/crates/convex_macro/src/lib.rs +++ b/crates/convex_macro/src/lib.rs @@ -135,16 +135,10 @@ pub fn instrument_future(_attr: TokenStream, item: TokenStream) -> TokenStream { let gen = quote! { #(#attrs)* #vis async fn #ident #generics (#inputs) #output { - let __instrument_name = ::common::tracing::cstr!(#ident); - let __instrument_loc = ::common::span_location!(); - let future = async move { + ::common::run_instrumented!( + #ident, #block - }; - ::common::tracing::InstrumentedFuture::new( - future, - __instrument_name, - __instrument_loc, - ).await + ) } }; gen.into()