-
Notifications
You must be signed in to change notification settings - Fork 676
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
tracing-subscriber: LocalTime
doesn't work by default on unix systems, no warning of --cfg unsound_local_offset
#1688
Comments
Whew, okay, I had no idea about this. Hmm. We should probably surface the feature flag in the docs, as well as adding a note. This was definitely not obvious from the
Yeah, this should probably be fixed. Previously, getting the timestamp itself was always infallible, and the error would only be returned if formatting it failed...which, because it's being written to a |
## Motivation Currently, `tracing_subscriber::fmt` will bail out of formatting the log line when formatting the timestamp fails. Previously, when timestamps were formatted using the `chrono` crate, this was the correct behavior, as getting the timestamp was infallible, and an error would only be returned if *formatting* the timestamp to the buffer fails. This should never actually happen, because we are writing the timestamp to a string, which should never fail; using `?` is just a bit more efficient than `.expect` because it doesn't require generating unwinding code. However, this is no longer the case when using the `time` crate. In the `time` API, actually getting a timestamp is fallible, and in some cases, will fail. The current code will bail out of formatting the entire log line if getting the timestamp fails, which is not great --- using the wrong timestamp formatter will result in silently dropping all log lines. ## Solution This branch changes the `format_timestamp` method to print `<unknown time>` when the timestamp formatting fails, rather than bailing. This way, we at least print the rest of the log line for the event. This fixes half of the issue described in #1688 (the other half is improving documentation).
## Motivation Currently, `tracing_subscriber::fmt` will bail out of formatting the log line when formatting the timestamp fails. Previously, when timestamps were formatted using the `chrono` crate, this was the correct behavior, as getting the timestamp was infallible, and an error would only be returned if *formatting* the timestamp to the buffer fails. This should never actually happen, because we are writing the timestamp to a string, which should never fail; using `?` is just a bit more efficient than `.expect` because it doesn't require generating unwinding code. However, this is no longer the case when using the `time` crate. In the `time` API, actually getting a timestamp is fallible, and in some cases, will fail. The current code will bail out of formatting the entire log line if getting the timestamp fails, which is not great --- using the wrong timestamp formatter will result in silently dropping all log lines. ## Solution This branch changes the `format_timestamp` method to print `<unknown time>` when the timestamp formatting fails, rather than bailing. This way, we at least print the rest of the log line for the event. This fixes half of the issue described in #1688 (the other half is improving documentation).
## Motivation The `time` crate must be compiled with `--cfg unsound_local_offset` in order for local timestamps to be enabled. For users whose first exposure to the `time` crate's API is via `tracing-subscriber`'s `time` timestamp formatters, this is potentially _very_ surprising! Therefore, although this cfg is not part of `tracing`'s API surface, we should probably document this aspect of `time`'s API in the `tracing-subscriber::fmt::time` documentation. ## Solution This branch adds warnings in the `time::LocalTime` type's API docs, in the struct-level documentation and on the `new` constructor, describing that `--cfg unsound_local_offset` is necessary to record local timestamps and referring users to the `time` documentation. I also added `unsound_local_offset` to the `doc(cfg(...))` attributes for the `LocalTime` type. While I was changing `tracing-subscriber`'s docs, I also fixed a couple formatting issues I noticed. Fixes #1688
## Motivation The `time` crate must be compiled with `--cfg unsound_local_offset` in order for local timestamps to be enabled. For users whose first exposure to the `time` crate's API is via `tracing-subscriber`'s `time` timestamp formatters, this is potentially _very_ surprising! Therefore, although this cfg is not part of `tracing`'s API surface, we should probably document this aspect of `time`'s API in the `tracing-subscriber::fmt::time` documentation. ## Solution This branch adds warnings in the `time::LocalTime` type's API docs, in the struct-level documentation and on the `new` constructor, describing that `--cfg unsound_local_offset` is necessary to record local timestamps and referring users to the `time` documentation. I also added `unsound_local_offset` to the `doc(cfg(...))` attributes for the `LocalTime` type. While I was changing `tracing-subscriber`'s docs, I also fixed a couple formatting issues I noticed. Fixes #1688
## Motivation Currently, `tracing_subscriber::fmt` will bail out of formatting the log line when formatting the timestamp fails. Previously, when timestamps were formatted using the `chrono` crate, this was the correct behavior, as getting the timestamp was infallible, and an error would only be returned if *formatting* the timestamp to the buffer fails. This should never actually happen, because we are writing the timestamp to a string, which should never fail; using `?` is just a bit more efficient than `.expect` because it doesn't require generating unwinding code. However, this is no longer the case when using the `time` crate. In the `time` API, actually getting a timestamp is fallible, and in some cases, will fail. The current code will bail out of formatting the entire log line if getting the timestamp fails, which is not great --- using the wrong timestamp formatter will result in silently dropping all log lines. ## Solution This branch changes the `format_timestamp` method to print `<unknown time>` when the timestamp formatting fails, rather than bailing. This way, we at least print the rest of the log line for the event. This fixes half of the issue described in #1688 (the other half is improving documentation).
## Motivation The `time` crate must be compiled with `--cfg unsound_local_offset` in order for local timestamps to be enabled. For users whose first exposure to the `time` crate's API is via `tracing-subscriber`'s `time` timestamp formatters, this is potentially _very_ surprising! Therefore, although this cfg is not part of `tracing`'s API surface, we should probably document this aspect of `time`'s API in the `tracing-subscriber::fmt::time` documentation. ## Solution This branch adds warnings in the `time::LocalTime` type's API docs, in the struct-level documentation and on the `new` constructor, describing that `--cfg unsound_local_offset` is necessary to record local timestamps and referring users to the `time` documentation. I also added `unsound_local_offset` to the `doc(cfg(...))` attributes for the `LocalTime` type. While I was changing `tracing-subscriber`'s docs, I also fixed a couple formatting issues I noticed. Fixes #1688
## Motivation Currently, `tracing_subscriber::fmt` will bail out of formatting the log line when formatting the timestamp fails. Previously, when timestamps were formatted using the `chrono` crate, this was the correct behavior, as getting the timestamp was infallible, and an error would only be returned if *formatting* the timestamp to the buffer fails. This should never actually happen, because we are writing the timestamp to a string, which should never fail; using `?` is just a bit more efficient than `.expect` because it doesn't require generating unwinding code. However, this is no longer the case when using the `time` crate. In the `time` API, actually getting a timestamp is fallible, and in some cases, will fail. The current code will bail out of formatting the entire log line if getting the timestamp fails, which is not great --- using the wrong timestamp formatter will result in silently dropping all log lines. ## Solution This branch changes the `format_timestamp` method to print `<unknown time>` when the timestamp formatting fails, rather than bailing. This way, we at least print the rest of the log line for the event. This fixes half of the issue described in #1688 (the other half is improving documentation).
## Motivation The `time` crate must be compiled with `--cfg unsound_local_offset` in order for local timestamps to be enabled. For users whose first exposure to the `time` crate's API is via `tracing-subscriber`'s `time` timestamp formatters, this is potentially _very_ surprising! Therefore, although this cfg is not part of `tracing`'s API surface, we should probably document this aspect of `time`'s API in the `tracing-subscriber::fmt::time` documentation. ## Solution This branch adds warnings in the `time::LocalTime` type's API docs, in the struct-level documentation and on the `new` constructor, describing that `--cfg unsound_local_offset` is necessary to record local timestamps and referring users to the `time` documentation. I also added `unsound_local_offset` to the `doc(cfg(...))` attributes for the `LocalTime` type. While I was changing `tracing-subscriber`'s docs, I also fixed a couple formatting issues I noticed. Fixes #1688
This change updates the tracing-subscriber dependency we consume to version 0.3. Note that we stop emitting local time stamps in traces with this change (i.e., they will now be for the UTC time zone). The new version comes with a 'local-time' feature state switch but unless we jump through huge hoops (and have to accept unsound code), trace messages are just silently swallowed. Please refer to tokio-rs/tracing#1688 for the glory details.
This change updates the tracing-subscriber dependency we consume to version 0.3. Note that we stop emitting local time stamps in traces with this change (i.e., they will now be for the UTC time zone). The new version comes with a 'local-time' feature state switch but unless we jump through huge hoops (and have to accept unsound code), trace messages are just silently swallowed. Please refer to tokio-rs/tracing#1688 for the glory details.
This change updates the tracing-subscriber dependency we consume to version 0.3. Note that we stop emitting local time stamps in traces with this change (i.e., they will now be for the UTC time zone). The new version comes with a 'local-time' feature state switch but unless we jump through huge hoops (and have to accept unsound code), trace messages are just silently swallowed. Please refer to tokio-rs/tracing#1688 for the glory details.
This change updates the tracing-subscriber dependency we consume to version 0.3. Note that we stop emitting local time stamps in traces with this change (i.e., they will now be for the UTC time zone). The new version comes with a 'local-time' feature state switch but unless we jump through huge hoops (and have to accept unsound code), trace messages are just silently swallowed. Please refer to tokio-rs/tracing#1688 for the glory details.
This change updates the tracing-subscriber dependency we consume to version 0.3. Note that we stop emitting local time stamps in traces with this change (i.e., they will now be for the UTC time zone). The new version comes with a 'local-time' feature state switch but unless we jump through huge hoops (and have to accept unsound code), trace messages are just silently swallowed. Please refer to tokio-rs/tracing#1688 for the glory details. We could use the recently added OffsetTime, but it has the downside of not reacting to time zone changes, which may cause confusion for a long running service. There is nothing wrong with emitting UTC time stamps, though, so that is what we do.
Bug Report
Version
Platform
Darwin DeerBook 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Crates
tracing-subscriber
Description
Attempting to use
.with_timer
with aLocalTime
argument cause all tracing events to vanish. The problem seems to be that on unix systems thetime
crate refuses to fetch the local offset without--cfg unsound_local_offset
, and this gets turned into an error which bubbles up through the formatting until it gets totracing_subscriber::fmt::FmtLayer::on_event()
which just throws away the error and logs nothing.This is rather surprising behavior, all the more-so that it isn't documented. Even the
time
crate itself doesn't give a good explanation of this feature, and doesn't warn thatOffsetDateTime::now_local()
doesn't work on unix systems without it. I only figured it out by looking through the source.It also seems to be rather poor behavior to throw away the whole tracing event because the local time offset couldn't be fetched. Surely there's some fallback behavior that could be used here. I'd suggest just falling back to UTC except if the time formatter doesn't show offset then this could be confusing. It could of course just fall back to the default timestamp formatter, as if I never called
.with_timer()
.In any case, I feel like at a minimum this should be documented properly, so it doesn't surprise everybody. And then I would suggest that
FormatTime
be extended with methods that allow for implementing easy fallback, so I can say e.g. "ifLocalTime
doesn't work, try this other formatter instead". And any error bubbled up fromFormatTime
should just result in using a default fallback instead of abandoning the whole event.The text was updated successfully, but these errors were encountered: