Skip to content

Commit 3fe498e

Browse files
committed
Use absolute timestamp format in JSON logs.
The current log format for the proxy shows the number of seconds since process start. This is fine for most cases, but can make logs processing and aggregation tricky, especially when using the JSON format. This changes the JSON format to always report the absolute timestamp instead of uptime. The existing format (using uptime in seconds) is preserved in the plain logs format, as it is still useful for debugging and the absolute timestamp can be retrieved using `kubectl logs --timestamp`. Example output with the env var set: ```json {"timestamp":"2024-09-09T13:38:56.913847Z","level":"DEBUG","fields":{"message":"Only allowing connections targeting `LINKERD2_PROXY_INBOUND_IPS`","allowed":"{10.42.0.48}"},"target":"linkerd_app::env","threadId":"ThreadId(1)"} {"timestamp":"2024-09-09T13:38:56.919918Z","level":"INFO","fields":{"message":"Using single-threaded proxy runtime"},"target":"linkerd2_proxy::rt","threadId":"ThreadId(1)"} ``` Fixes [#12505](linkerd/linkerd2#12505) Signed-off-by: Scott Fleener <[email protected]>
1 parent f82de85 commit 3fe498e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

linkerd/tracing/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl Settings {
110110
S: Send + Sync,
111111
{
112112
let fmt = tracing_subscriber::fmt::format()
113-
.with_timer(self.timer())
113+
// Always use absolute system time instead of uptime in JSON.
114+
.with_timer(tracing_subscriber::fmt::time::SystemTime)
114115
.with_thread_ids(!self.is_test)
115116
// Configure the formatter to output JSON logs.
116117
.json()

0 commit comments

Comments
 (0)