Skip to content

feat(fastrace-futures): add StreamExt::enter_on_poll#174

Merged
andylokandy merged 1 commit into
fast:mainfrom
TennyZhuang:stream-ext-172
May 4, 2026
Merged

feat(fastrace-futures): add StreamExt::enter_on_poll#174
andylokandy merged 1 commit into
fast:mainfrom
TennyZhuang:stream-ext-172

Conversation

@TennyZhuang
Copy link
Copy Markdown
Contributor

Adds StreamExt::enter_on_poll to fastrace-futures, mirroring fastrace::future::FutureExt::enter_on_poll.

EnterOnPollStream creates a LocalSpan on every Stream::poll_next(), useful for observing how often a stream is woken.

Closes #172

Copy link
Copy Markdown
Collaborator

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM. Thanks for your contribution @TennyZhuang!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds stream-level poll instrumentation to fastrace-futures, enabling lightweight per-poll_next local spans similar to fastrace::future::FutureExt::enter_on_poll, primarily to observe wake/poll frequency in long-lived streams.

Changes:

  • Add StreamExt::enter_on_poll and EnterOnPollStream adapter to create a LocalSpan on each poll_next.
  • Add unit tests verifying span creation, parent/child relationships, and span completion on drop.
  • Update dev-dependencies to enable fastrace and run reporter-dependent tests serially.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
fastrace-futures/src/lib.rs Implements enter_on_poll for streams and adds tests validating behavior and span relationships.
fastrace-futures/Cargo.toml Adds dev-deps needed for span-reporting tests (fastrace with enable, serial_test).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fastrace-futures/Cargo.toml Outdated
fastrace = { workspace = true, features = ["enable"] }
async-stream = { version = "0.3" }
futures = { version = "0.3" }
serial_test = { version = "3.1" }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid adding serial_test here. This adapter can be tested through a local collection path instead of the process-global reporter: start a LocalCollector, poll a simple stream under a local parent, then inspect LocalSpans::to_span_records(...). That would keep the test focused and avoid a new dev dependency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. serial_test removed; tests now use LocalCollector::start()collector.collect()to_span_records(...).

}
}

/// Starts a [`LocalSpan`] at every [`Stream::poll_next()`].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention that this needs an outer in_span or another existing local parent? The example uses the right order, but spelling it out would help avoid .in_span(...).enter_on_poll(...), where the local span is entered before the local parent exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added an "Important: Local parent required" section that spells out the need for an outer in_span or existing local parent, shows the correct .enter_on_poll().in_span() order, and warns against the reversed order.

Adds `enter_on_poll` to `StreamExt`, mirroring `FutureExt::enter_on_poll`.
Creates a `LocalSpan` on every `Stream::poll_next()`.

Changes from review:
- Remove serial_test dev-dependency
- Rewrite tests to use LocalCollector + LocalSpans::to_span_records()
- Strengthen docs to warn about composition order and local parent requirement

Closes fast#172
@TennyZhuang
Copy link
Copy Markdown
Contributor Author

@andylokandy Both review items addressed in the latest push:

  1. Removed serial_test — dev-dependency deleted. Tests now use LocalCollector::start() → poll stream → collector.collect()local_spans.to_span_records(parent_ctx). No global reporter needed.

  2. Docs strengthened — Added an "Important: Local parent required" section that explicitly states enter_on_poll needs an outer in_span or pre-existing local parent. It shows the correct composition .enter_on_poll("poll").in_span(span) and a warning block for the wrong order .in_span(span).enter_on_poll("poll").

CI is re-running now. Thanks for the review!

@andylokandy andylokandy merged commit eb9ddab into fast:main May 4, 2026
11 checks passed
@andylokandy
Copy link
Copy Markdown
Collaborator

@TennyZhuang Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream instrumentation utility (equivalent to tracing_futures::Instrument for Streams)

4 participants