Skip to content

Include Tokio task ID in messages #3517

@ongardie-atomix

Description

@ongardie-atomix

Feature Request

Crates

tracing-subscriber

Motivation

I'm using tracing as sort of a fancy log at the moment, using events but not really using spans. I'd like to see the Tokio task ID on events, where applicable, which can help correlate between events.

Proposal

Would you be open to an implementation similar to the current thread IDs (as added in #818)? When formatting the message, we could call tokio::task::try_id. This would be disabled by default, of course.

Since this function is defined in tokio and gated by feature rt, I think we'd need to add tokio with rt as an optional dependency to tracing-subscriber.

Alternatives

Maybe I'm supposed to use spans to solve this problem in a different way. I think spans make more sense when you have infrastructure set up to consume them and present them in a useful way, but I might be wrong about that.

I don't see a way to get a Tokio task's name, but if that's ever exposed then that would be another thing to include, similar to thread name.

An alternative approach would be to allow whatever sets up the formatter to pass in extra fields or pass in a function that returns the task ID/name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions