Skip to content

tracing_subscriber: Add with_os_thread_ids #3362

@tgross35

Description

@tgross35

Feature Request

Crates

tracing_subscriber

Motivation

On the current nightly, the thread ID is now printed as part of the panic messages:

thread 'main' (13) panicked at src/main.rs:2:5:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It would be nice to have an easy way to coordinate this with tracing events, as well as with debugger output and process managers.

Proposal

Add the following:

  • Layer::with_os_thread_ids
  • SubscriberBuilder::with_os_thread_ids
  • Format::with_os_thread_ids

This matches with_thread_ids in each of the same places.

Unfortunately there is no way to get the OS TID in std: not sure whether this is a dealbreaker or not. It is a simple libc call on most platforms:

https://github.com/rust-lang/rust/blob/898aff704d6f0d00343f21d31b8b9bfac8e43007/library/std/src/sys/pal/unix/thread.rs#L401-L455

https://github.com/rust-lang/rust/blob/898aff704d6f0d00343f21d31b8b9bfac8e43007/library/std/src/sys/pal/windows/thread.rs#L130-L136

(there is a gettid crate but it is broken, and I don't think there is any need to pull in a crate for 3-6 definitions).

Alternatives

with_thread_ids could be changed to emit the OS TID.

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