tower-rs / tower-http

HTTP specific Tower utilities.
675 stars 156 forks source link

Trace time is not server time #452

Closed b4too closed 8 months ago

b4too commented 8 months ago

Thank you for your work on tower, for a beginner such as myself it is of great help ! I do however have a question that I will detail below :

Bug Report

The time reported with the trace module is from UTC timezone, which is different from my server's timezone. I could not find a method to have a custom timezone, nor an issue regarding this (perhaps intended) behavior.

Version

tower-http = { version = "0.5.0", features = ["fs", "trace"] }

Platform

Debian amd64

Description

Using such a layer on my Axum Router :

.layer(
            TraceLayer::new_for_http()
                .make_span_with(
                    trace::DefaultMakeSpan::new()
                        .level(Level::INFO)
                        .include_headers(true),
                )
                .on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
        );

gives this log for instance : 2023-12-26T15:32:41.576752Z INFO request: finished processing request latency=0 ms status=200 method=GET uri=/ version=HTTP/1.1 headers={...} which is 1h earlier than my current timezone.

Thank you for your help !

jplatte commented 8 months ago

This is tracing-subcriber's output format, tower-http doesn't really have anything to do with it. IIRC the Z at the end of the timestamp signifies a UTC timestamp.

Please check tracing-subcriber's documentation about whether it's possible to print timestamps in the OS'es timezone instead, and open an issue there if not.

b4too commented 8 months ago

Thanks for your response, you were right of course, I eventually changed the log time to local time with the with_timer() method from tracing-subscriber as described here.