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

tracing: add resource instrumentation using declarative macros #3933

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio/src/fs/file.rs
Expand Up @@ -210,7 +210,7 @@ impl File {
});

new_instrumented_resource! {
FileSystem,
"fileSystem",
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
File {
std,
inner,
Expand Down
15 changes: 7 additions & 8 deletions tokio/src/macros/instrument.rs
Expand Up @@ -46,16 +46,16 @@ cfg_trace! {

macro_rules! new_instrumented_resource {
(
$resource_type:ident,
$resource_type:literal,
$struct:ident {
$($field:ident),* $(,)* // Handle non shorthand initialization
}
) => {
$struct {
resource_span:tracing::trace_span!(
resource_span: tracing::trace_span!(
"resource",
concrete_type = stringify!($struct),
kind = stringify!($resource_type)
kind = $resource_type
),
$(
$field,
Expand All @@ -71,7 +71,7 @@ cfg_trace! {
$body:block
) => {
$vis fn $name(&mut $self, $($arg_name : $arg_ty,)*) $(-> $ret)? {
let __resource_span_guard = $self.resource_span.enter();
let _resource_span_guard = $self.resource_span.enter();
$body
}
};
Expand All @@ -81,7 +81,7 @@ cfg_trace! {
$body:block
) => {
$vis fn $name(&$self, $($arg_name : $arg_ty,)*) $(-> $ret)? {
let __resource_span_guard = $self.resource_span.enter();
let _resource_span_guard = $self.resource_span.enter();
$body
}
};
Expand All @@ -91,8 +91,7 @@ cfg_trace! {
$body:block
) => {
$vis fn $name($self : $self_type, $($arg_name : $arg_ty,)*) $(-> $ret)? {
let span = $self.resource_span.clone();
let __resource_span_guard = span.enter();
let _span = $self.resource_span.clone().entered();
$body
}
};
Expand All @@ -112,7 +111,7 @@ cfg_not_trace! {
}

macro_rules! new_instrumented_resource {
($resource_type:ident, $($t:tt)*) => {
($resource_type:literal, $($t:tt)*) => {
$($t)*
}
}
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/tcp/stream.rs
Expand Up @@ -155,7 +155,7 @@ impl TcpStream {

pub(crate) fn new(connected: mio::net::TcpStream) -> io::Result<TcpStream> {
let io = PollEvented::new(connected)?;
Ok(new_instrumented_resource!(Network, TcpStream { io }))
Ok(new_instrumented_resource!("network", TcpStream { io }))
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
}

/// Creates new `TcpStream` from a `std::net::TcpStream`.
Expand Down Expand Up @@ -190,7 +190,7 @@ impl TcpStream {
pub fn from_std(stream: std::net::TcpStream) -> io::Result<TcpStream> {
let io = mio::net::TcpStream::from_std(stream);
let io = PollEvented::new(io)?;
Ok(new_instrumented_resource!(Network, TcpStream { io }))
Ok(new_instrumented_resource!("network", TcpStream { io }))
seanmonstar marked this conversation as resolved.
Show resolved Hide resolved
}

/// Turn a [`tokio::net::TcpStream`] into a [`std::net::TcpStream`].
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/time/driver/sleep.rs
Expand Up @@ -171,7 +171,7 @@ impl Sleep {
let handle = Handle::current();
let entry = TimerEntry::new(&handle, deadline);

new_instrumented_resource!(Timer, Sleep { deadline, entry })
new_instrumented_resource!("timer", Sleep { deadline, entry })
}

pub(crate) fn far_future() -> Sleep {
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/fs_file_mocked.rs
Expand Up @@ -29,7 +29,7 @@ macro_rules! instrument_resource {
}

macro_rules! new_instrumented_resource {
($resource_type:ident, $($t:tt)*) => {
($resource_type:literal, $($t:tt)*) => {
$($t)*
}
}
Expand Down