-
Notifications
You must be signed in to change notification settings - Fork 707
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
#[instrument]
incorrect for fn() -> impl Future
and async move
block
#1863
Comments
The expanded output looks like this: fn lazy() -> impl Future<Output = ()> {
{}
#[allow(clippy::suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
{
__tracing_attr_span = {
use ::tracing::__macro_support::Callsite as _;
static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
use ::tracing::__macro_support::MacroCallsite;
static META: ::tracing::Metadata<'static> = {
::tracing_core::metadata::Metadata::new(
"lazy",
"lazy_futures",
tracing::Level::INFO,
Some("playground\\lazy-futures\\src\\main.rs"),
Some(10u32),
Some("lazy_futures"),
::tracing_core::field::FieldSet::new(
&[],
::tracing_core::callsite::Identifier(&CALLSITE),
),
::tracing::metadata::Kind::SPAN,
)
};
MacroCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
&& {
interest = CALLSITE.interest();
!interest.is_never()
}
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
} else {
let span = CALLSITE.disabled_span();
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy::suspicious_else_formatting)]
{
async move {
{
// log happens on *poll*
};
}
}
}
}
fn hybrid() -> impl Future<Output = ()> {
{}
#[allow(clippy::suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
{
__tracing_attr_span = {
use ::tracing::__macro_support::Callsite as _;
static CALLSITE: ::tracing::__macro_support::MacroCallsite = {
use ::tracing::__macro_support::MacroCallsite;
static META: ::tracing::Metadata<'static> = {
::tracing_core::metadata::Metadata::new(
"hybrid",
"lazy_futures",
tracing::Level::INFO,
Some("playground\\lazy-futures\\src\\main.rs"),
Some(23u32),
Some("lazy_futures"),
::tracing_core::field::FieldSet::new(
&[],
::tracing_core::callsite::Identifier(&CALLSITE),
),
::tracing::metadata::Kind::SPAN,
)
};
MacroCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if tracing::Level::INFO <= ::tracing::level_filters::STATIC_MAX_LEVEL
&& tracing::Level::INFO <= ::tracing::level_filters::LevelFilter::current()
&& {
interest = CALLSITE.interest();
!interest.is_never()
}
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
::tracing::Span::new(meta, &{ meta.fields().value_set(&[]) })
} else {
let span = CALLSITE.disabled_span();
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy::suspicious_else_formatting)]
{
{
// log happens on *call*
};
async move {
{
// log happens on *poll*
};
}
}
}
} |
Hmm, yeah, this codegen is not great. It would be nice to be able to enter the span for both any code that happens in the function body before the async block, and instrument the returned future in the async block. Thanks for working on this! |
Was this fixed by #1866? I was just looking for some clues on whether |
I don’t think I have fully solved this, unless someone else has done so in the meantime. |
I just came across another interesting case: A function returning I think for more complex cases like that, maybe it's not worth it to attempt to instrument the returned future(s)? The return type could even be a custom generic type containing a future, where it might not be possible, or is at least impossible to know how to, instrument that. Anyways, I'll just use |
Bug Report
Version
0.1.29
Description
I have recently experimented with various lazy/non-lazy
fn() -> impl Future
code, as there are subtle differences that can break other code.For me details, I have written a blog about Non-Lazy Futures Considered Harmful with a
tracing
specific example.Playing around a bit more, I found out that
#[instrument]
also does the wrong thing in certain situations.This leads to the following output:
It seems that the
async move
blocks in both thelazy
andhybrid
functions are not being correctly instrumented.I can take a look at this in more detail and work towards a fix.
The text was updated successfully, but these errors were encountered: