Skip to content

Commit

Permalink
Leave no trace when not tracy-tracing (#32648)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 3b1186e9668567685b200e922eec9e52b0f7ea4a
  • Loading branch information
goffrie authored and Convex, Inc. committed Dec 28, 2024
1 parent 4822dd4 commit bbbf5f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
49 changes: 14 additions & 35 deletions crates/common/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<F: Future> {
#[pin]
inner: F,
}

pub struct NoopLocation;

impl<F: Future> InstrumentedFuture<F> {
pub fn new(inner: F, _name: &'static CStr, _loc: &'static NoopLocation) -> Self {
Self { inner }
}
}

impl<F: Future> Future for InstrumentedFuture<F> {
type Output = F::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();
this.inner.poll(cx)
}
}

pub struct NoopSpan;

#[macro_export]
Expand All @@ -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,
};
12 changes: 3 additions & 9 deletions crates/convex_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bbbf5f1

Please sign in to comment.