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

meta: Task Builder stabilization #4114

Open
1 of 2 tasks
seanmonstar opened this issue Sep 16, 2021 · 4 comments
Open
1 of 2 tasks

meta: Task Builder stabilization #4114

seanmonstar opened this issue Sep 16, 2021 · 4 comments
Labels
A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-task Module: tokio/task M-tracing Tracing support in Tokio

Comments

@seanmonstar
Copy link
Member

This is to track the currently unstable tokio::task::Builder API. To use it, you must pass --cfg tokio_unstable to rustc.

RFC: https://hackmd.io/Vm0UXvrNTg6HleGlD8C8sg
PR: #3881

Roadmap

  • Include code from PR in a crates.io release
  • Resolve open questions

Open questions

  • How do we allow adding more context to the spawned task's tracing span?
    • If tracing is at 1.0, we could allow passing Builder::span directly.
    • To hide tracing, we could use some imaginary Builder::tag(name, value) that uses Span::record internally.
    • Or we could maybe make use of valuable
@seanmonstar seanmonstar added C-enhancement Category: A PR with an enhancement or bugfix. A-tokio Area: The main tokio crate M-task Module: tokio/task M-tracing Tracing support in Tokio labels Sep 16, 2021
@dan-da
Copy link

dan-da commented Dec 26, 2023

I might be missing something, but I don't see yet how to access the name after a task is spawned with tokio::task::Builder.

When using std::thread::Builder, one can access the name via join_handle.thread().name(), but I don't see any equivalent in tokio's JoinHandle.

use case: This would be useful for me in order to log task name when acquiring a lock, for example.

@Darksonn
Copy link
Contributor

Currently, the name is only accessible via the tracing traces that Tokio emits when you enable the unstable tracing feature.

@dan-da
Copy link

dan-da commented Dec 27, 2023

Currently, the name is only accessible via the tracing traces that Tokio emits when you enable the unstable tracing feature.

yes, the name is dropped here and I find that unfortunate. And even if tracing feature is enabled, the name is still not available via API.

I don't see why Builder and name should be gated behind tracing feature at all, when the concept of a named task seems generally usefully, not only for tracing. And again, it would be symmetric with functionality already offered in (stable) std::thread.

The alternative for an app wanting to keep track of named tasks is to do it themselves at each call to spawn(), eg with a struct that contains a name and a JoinHandle. This is a viable workaround, but is much less convenient eg to access within the spawned thread, and if I were moving code that already uses std::thread::Builder to tokio tasks, it would be burdensome.

Maybe this should be opened as a new issue? Anyway it seems (to me) like something that should be addressed before the Builder feature is stabilized.

@Darksonn
Copy link
Contributor

The reason it's gated behind the tracing feature is that the feature was added for that specific purpose.

Still, I agree that it would be reasonable to expand this and stabilize it for other use-cases.

@mox692 mox692 mentioned this issue Jun 1, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-task Module: tokio/task M-tracing Tracing support in Tokio
Projects
None yet
Development

No branches or pull requests

3 participants