Skip to content

subscriber: re-introduce chrono types and feature flags #2080

@davidbarsky

Description

@davidbarsky

Feature Request

Crates

  • This proposed change impacts tracing-subscriber.

Motivation

It is impossible to soundly to use tracing_subscriber::fmt::time::LocalTime or [tracing_subscriber::fmt::time::OffsetTime] in any multithreaded environment because any call to setenv will immediately make accessing any environment variable unsound via a use-after-free. On unix systems, the time crate checks whether the binary is running in an single-threaded environment. If the binary has multiple threads running, time does not return the local offset as the platform's libc will call getenv("TZ") to determine the local timezone.

Unfortunately, my employer has patched the Rust toolchain to default to jemalloc as the default, system allocator. On startup, jemalloc spins up background thread(s), which means that time will never return the local time.

Proposal

Chrono has reimplemented the timezone database file parsing chronotope/chrono#674. This removes the need to check whether other threads are running, as time currently does. Once this feature lands, I propose that we reintroduce Chrono-specific timers under a chrono feature flag. These will be similar to the Chrono timers in tracing-subscriber 0.2. I'm not sure how to handle the tracing_subscriber::fmt::time::FormatTime trait, as it is currently tied to time's formatters, not chrono's.

If both time and chrono are activated as feature flags, then time should remain the default formatter for fmt::{Layer, Subscriber}, but this default can be revisited as part of tracing-subscriber 0.4. If time adopts a similar approach to chrono's (as tracked in time-rs/time#193), we can evaluate what formatting is needed or required in tracing-subscriber, but this is out of scope for this issue.

Alternatives

The alternative is that this feature shouldn't be added, but this would pose a non-trivial blocker to using tracing-subscriber in certain environments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/subscriberRelated to the `tracing-subscriber` cratekind/featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions