-
Notifications
You must be signed in to change notification settings - Fork 726
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
Consider entering Span
on Drop
for Instrumented
#2541
Comments
Here's a contrived example of the same problem happening with use std::future::{pending, ready};
use futures::FutureExt as _;
#[tracing::instrument]
async fn foo(switch: bool) -> i32 {
let val = LogOnDrop;
match switch {
true => ready(1).await,
false => pending::<i32>().await,
}
}
#[tokio::test]
async fn main() {
tracing_subscriber::fmt().init();
// polled to completion
assert!(foo(true).now_or_never().is_some());
// polled once and thrown away mid-execution
assert!(foo(false).now_or_never().is_none());
}
struct LogOnDrop;
impl Drop for LogOnDrop {
fn drop(&mut self) {
tracing::info!("drop");
}
} Output:
|
Hmm, this isn't a bad idea. I agree that it's potentially desirable to have any events occurring inside a One potential challenge is that it would be necessary to actually ensure that the inner |
We could possibly avoid |
IMO using |
This comment was marked as resolved.
This comment was marked as resolved.
I actually myself already implemented version with |
@ilslv as being released in 0.1.38, I guess we may close this issue now. |
Feature Request
Crates
tracing
,tracing-futures
Motivation
Sometimes it's desired to get
Span
insideDrop
implementation. For example:The problem is there is difference between when
Drop
can be actually called: insideFuture::poll()
or onDrop
of the entireFuture
:Output:
Span is missing for a second log.
Proposal
Would you accept a PR adding
Drop
implementation forInstrumented
, that will enter theSpan
andDrop
innerFuture
?Alternatives
Leave it as is.
The text was updated successfully, but these errors were encountered: