Skip to content

Commit

Permalink
Correctly instrument non-lazy Futures functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jan 28, 2022
1 parent 820613c commit 94754de
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,40 @@ fn manual_impl_future() {
#[allow(clippy::manual_async_fn)]
#[instrument]
fn manual_impl_future() -> impl Future<Output = ()> {
tracing::trace!(call = true);
async {
tracing::trace!(poll = true);
}
}

let span = span::mock().named("manual_impl_future");
let call_event = || event::mock().with_fields(field::mock("call").with_value(&true));
let poll_event = || event::mock().with_fields(field::mock("poll").with_value(&true));

let (collector, handle) = collector::mock()
// await manual_impl_future
// call/drop manual_impl_future
.new_span(span.clone())
.enter(span.clone())
.event(call_event())
.exit(span.clone())
.drop_span(span.clone())
// call/await manual_impl_future
.new_span(span.clone())
.enter(span.clone())
.event(call_event())
.exit(span.clone())
.enter(span.clone())
.event(poll_event())
.exit(span.clone())
.drop_span(span)
.done()
.run_with_handle();

with_default(collector, || {
// call only, no poll
drop(manual_impl_future());

// call and poll
block_on_future(async {
manual_impl_future().await;
});
Expand All @@ -408,25 +423,41 @@ fn manual_impl_future() {
fn manual_box_pin() {
#[instrument]
fn manual_box_pin() -> Pin<Box<dyn Future<Output = ()>>> {
tracing::trace!(call = true);
Box::pin(async {
tracing::trace!(poll = true);
})
}

let span = span::mock().named("manual_box_pin");

let call_event = || event::mock().with_fields(field::mock("call").with_value(&true));
let poll_event = || event::mock().with_fields(field::mock("poll").with_value(&true));

let (collector, handle) = collector::mock()
// await manual_box_pin
// call/drop manual_box_pin
.new_span(span.clone())
.enter(span.clone())
.event(call_event())
.exit(span.clone())
.drop_span(span.clone())
// call/await manual_box_pin
.new_span(span.clone())
.enter(span.clone())
.event(call_event())
.exit(span.clone())
.enter(span.clone())
.event(poll_event())
.exit(span.clone())
.drop_span(span)
.done()
.run_with_handle();

with_default(collector, || {
// call only, no poll
drop(manual_box_pin());

// call and poll
block_on_future(async {
manual_box_pin().await;
});
Expand Down

0 comments on commit 94754de

Please sign in to comment.