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

Replace chrono with time 0.3 #1598

Closed
vilgotf opened this issue Sep 29, 2021 · 8 comments · Fixed by #1646
Closed

Replace chrono with time 0.3 #1598

vilgotf opened this issue Sep 29, 2021 · 8 comments · Fixed by #1646
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/feature New feature or request

Comments

@vilgotf
Copy link

vilgotf commented Sep 29, 2021

Feature Request

Crates

tracing-subscriber

Motivation

to reduce the amount of dependencies: chrono pulls in libc and num-integer whereas time has zero deps.

Proposal

Replace chrono with time. chrono hasn't seen a commit in 8 months whereas time is actively developed (although time has a much higher MSRV, 0.3.0 has 1.48 and 0.3.3 has 1.51).

Alternatives

humantime is another zero dep crate that could be pulled in, but it doesn't offer alternatives for ChronoLocal. ChronoLocal could be removed in an API rewrite of the time module but that's a larger effort than what I'm proposing.

@hawkw
Copy link
Member

hawkw commented Oct 4, 2021

Hmm, we currently have a constructor for a time format that takes a chrono strftime format string and formats timestamps using that format:

/// Format the time using the given format string.
///
/// See [`chrono::format::strftime`]
/// for details on the supported syntax.
///
pub fn with_format(format_string: String) -> Self {
ChronoLocal {
format: ChronoFmtType::Custom(format_string),
}
}

I see that the time also has an API for formatting timestamps with a formatting string, but it's not clear to me whether it will accept the same syntax. So, it would be nice to know if replacing that function with the time crate's alternative would be breaking or not.

Another thing that's worth noting, though, is that the chrono dependency is feature flagged. Thus, rather than replacing the existing formatters with the time crate, we could simply add a new feature flag for the time crate, and add timestamp formatting implementations that use time. This way, it would be fine if time's formatting string syntax is different. This also has the advantage that if users are already using chrono or time in their project, they can pick the dependency that's already in their dependency tree. We could add a feature for humantime as well. We would have separate APIs for each of these crates' timestamp formatting implementations that are enabled based on their various feature flags, so the fact that humantime can't implement all the same APIs as chrono wouldn't be an issue in this case.

This also has the nice advantage of avoiding having APIs with names like ChronoLocal and ChronoUtc that actually don't use the chrono crate at all, which seems potentially confusing...

The one issue is that, while chrono is feature-flagged, it is currently enabled by default:

default = ["env-filter", "smallvec", "fmt", "ansi", "chrono", "tracing-log", "json"]

so, if users want to use humantime or time instead, and avoid depending on chrono, they'd have to add default-features = false to their tracing-subscriber dependency.

In the future, it would probably be better to change the default features so that no external timestamp formatting dependency is on by default, since tracing-subscriber has its own simple formatting implementation that's used when no external timestamp formatter is enabled. However, removing a default feature is a breakign change, so that would have to wait until tracing-subscriber 0.3.

What do you think of the proposal of adding time (and humantime) as separate, feature-flagged APIs, rather than replacing the implementation of the currently provided chrono formatters?

@hawkw hawkw added crate/subscriber Related to the `tracing-subscriber` crate kind/feature New feature or request labels Oct 4, 2021
@vilgotf
Copy link
Author

vilgotf commented Oct 4, 2021

To qualify I'd like to say that I have little experience with tracing-subscribers API (having only used it in simple setups) and I wasn't even aware that tracing-subscriber had an internal (human readable)1 time formatting implementation.

I like your proposal of disabling custom timestamp formatting by default, since most users don't need it. As time and chrono are ~even in popularity I think it makes sense to support both for the time being and users can, as you're saying, use what they're already using.

Also, having looked more into humantime I'm not sure that it's appropriate here: my understanding is that it's for predefined formats. On another note, enabling the formatting feature of time pulls in itoa so it wouldn't have zero deps :(

Footnotes

  1. when I say human readable I include YYYY-MM-DD etc. (essentially everything that's not a unix timestamp)

@hawkw
Copy link
Member

hawkw commented Oct 4, 2021

Also, having looked more into humantime I'm not sure that it's appropriate here: my understanding is that it's for predefined formats. On another note, enabling the formatting feature of time pulls in itoa so it wouldn't have zero deps :(

humantime has RFC 3339 formatting, so I think it might be worth providing it as an option --- it might be the lightest-weight way to get an RFC 3339 formatter, if you don't need the other functionality provided by time or chrono?

@vilgotf
Copy link
Author

vilgotf commented Oct 5, 2021

humantime has RFC 3339 formatting, so I think it might be worth providing it as an option --- it might be the lightest-weight way to get an RFC 3339 formatter, if you don't need the other functionality provided by time or chrono?

I suppose so

@jplatte
Copy link
Member

jplatte commented Oct 18, 2021

This just a lot more urgent because time has (had) a vulnerability that doesn't seem like it will be fixed in 0.1.x, and chrono builds on that old version. There's a PR that would bump the time version used by chrono but it's not at all clear whether it will receive maintainer attention soon-ish.

@hawkw
Copy link
Member

hawkw commented Oct 18, 2021

This just a lot more urgent because time has (had) a vulnerability that doesn't seem like it will be fixed in 0.1.x, and chrono builds on that old version. There's a PR that would bump the time version used by chrono but it's not at all clear whether it will receive maintainer attention soon-ish.

Yeah, we will probably be publishing a v0.3 of tracing-subscriber today that replaces the chrono dependency with a dependency on time 0.2. We can re-add a chrono API in v0.3 (under a default-off feature flag) once the vulnerability is fixed.

@jplatte
Copy link
Member

jplatte commented Oct 18, 2021

with a dependency on time 0.2.

Do you really mean 0.2, or 0.3 (latest)?

@hawkw
Copy link
Member

hawkw commented Oct 18, 2021

with a dependency on time 0.2.

Do you really mean 0.2, or 0.3 (latest)?

Sorry, I meant 0.3.

hawkw added a commit that referenced this issue Oct 18, 2021
## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see #1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes #1598.
hawkw added a commit that referenced this issue Oct 18, 2021
)

## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see #1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes #1598.
hawkw added a commit that referenced this issue Oct 21, 2021
)

## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see #1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes #1598.
hawkw added a commit that referenced this issue Oct 21, 2021
)

## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see #1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes #1598.
hawkw pushed a commit that referenced this issue Oct 22, 2021
## Motivation

This PR continues the work started in
#1646 to replace `chrono` with
`time`. I'll refer to @hawkw's motivation:

> Currently, `tracing-subscriber` supports the `chrono` crate for
> timestamp formatting, via a default-on feature flag. When this code
> was initially added to `tracing-subscriber`, the `time` crate did not
> have support for the timestamp formatting options we needed.
>
> Unfortunately, the `chrono` crate's maintenance status is now in
> question (see #1598). Furthermore, `chrono` depends on version 0.1 of
> the `time` crate, which contains a security vulnerability
> (https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
> vulnerability is fixed in more recent releases of `time`, but `chrono`
> still uses v0.1.

## Solution

I've replaced chrono with time 0.3. Unfortunately, some of chrono's
builders for DateTimes are not present in `time`, which required the
usage of `macro_rules!` macros to construct some of the hard-coded
times. I also took the opportunity to tidy some of the tests and change
the internal representation of `Rotation::NEVER` from year 9,999 to an
`Option::None`.

This branch changes `tracing-appender`'s MSRV from Rust 1.42 to Rust
1.51, the MSRV for the `time` crate when certain required feature flags
are enabled. This does *not* effect the MSRV for other crates in this
repository.
hawkw pushed a commit that referenced this issue Oct 22, 2021
## Motivation

This PR continues the work started in
#1646 to replace `chrono` with
`time`. I'll refer to @hawkw's motivation:

> Currently, `tracing-subscriber` supports the `chrono` crate for
> timestamp formatting, via a default-on feature flag. When this code
> was initially added to `tracing-subscriber`, the `time` crate did not
> have support for the timestamp formatting options we needed.
>
> Unfortunately, the `chrono` crate's maintenance status is now in
> question (see #1598). Furthermore, `chrono` depends on version 0.1 of
> the `time` crate, which contains a security vulnerability
> (https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
> vulnerability is fixed in more recent releases of `time`, but `chrono`
> still uses v0.1.

## Solution

I've replaced chrono with time 0.3. Unfortunately, some of chrono's
builders for DateTimes are not present in `time`, which required the
usage of `macro_rules!` macros to construct some of the hard-coded
times. I also took the opportunity to tidy some of the tests and change
the internal representation of `Rotation::NEVER` from year 9,999 to an
`Option::None`.

This branch changes `tracing-appender`'s MSRV from Rust 1.42 to Rust
1.51, the MSRV for the `time` crate when certain required feature flags
are enabled. This does *not* effect the MSRV for other crates in this
repository.
hawkw pushed a commit that referenced this issue Oct 22, 2021
## Motivation

This PR continues the work started in
#1646 to replace `chrono` with
`time`. I'll refer to @hawkw's motivation:

> Currently, `tracing-subscriber` supports the `chrono` crate for
> timestamp formatting, via a default-on feature flag. When this code
> was initially added to `tracing-subscriber`, the `time` crate did not
> have support for the timestamp formatting options we needed.
>
> Unfortunately, the `chrono` crate's maintenance status is now in
> question (see #1598). Furthermore, `chrono` depends on version 0.1 of
> the `time` crate, which contains a security vulnerability
> (https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
> vulnerability is fixed in more recent releases of `time`, but `chrono`
> still uses v0.1.

## Solution

I've replaced chrono with time 0.3. Unfortunately, some of chrono's
builders for DateTimes are not present in `time`, which required the
usage of `macro_rules!` macros to construct some of the hard-coded
times. I also took the opportunity to tidy some of the tests and change
the internal representation of `Rotation::NEVER` from year 9,999 to an
`Option::None`.

This branch changes `tracing-appender`'s MSRV from Rust 1.42 to Rust
1.51, the MSRV for the `time` crate when certain required feature flags
are enabled. This does *not* effect the MSRV for other crates in this
repository.
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
…kio-rs#1646)

## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see tokio-rs#1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes tokio-rs#1598.
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
This PR continues the work started in
tokio-rs#1646 to replace `chrono` with
`time`. I'll refer to @hawkw's motivation:

> Currently, `tracing-subscriber` supports the `chrono` crate for
> timestamp formatting, via a default-on feature flag. When this code
> was initially added to `tracing-subscriber`, the `time` crate did not
> have support for the timestamp formatting options we needed.
>
> Unfortunately, the `chrono` crate's maintenance status is now in
> question (see tokio-rs#1598). Furthermore, `chrono` depends on version 0.1 of
> the `time` crate, which contains a security vulnerability
> (https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
> vulnerability is fixed in more recent releases of `time`, but `chrono`
> still uses v0.1.

I've replaced chrono with time 0.3. Unfortunately, some of chrono's
builders for DateTimes are not present in `time`, which required the
usage of `macro_rules!` macros to construct some of the hard-coded
times. I also took the opportunity to tidy some of the tests and change
the internal representation of `Rotation::NEVER` from year 9,999 to an
`Option::None`.

This branch changes `tracing-appender`'s MSRV from Rust 1.42 to Rust
1.51, the MSRV for the `time` crate when certain required feature flags
are enabled. This does *not* effect the MSRV for other crates in this
repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants