Skip to content

Add latency in nanoseconds as a response log field#1258

Open
tab1293 wants to merge 1 commit into
imgproxy:masterfrom
playback-sports:log-response-latency
Open

Add latency in nanoseconds as a response log field#1258
tab1293 wants to merge 1 commit into
imgproxy:masterfrom
playback-sports:log-response-latency

Conversation

@tab1293

@tab1293 tab1293 commented Mar 19, 2024

Copy link
Copy Markdown

This change adds the latency of a request as a response log field. This is useful when filtering logs in Google Cloud logging for requests that have high latencies.

@DarthSim DarthSim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tab1293!

Thanks for the PR! I'm ok with adding latency to the logs but take a look at my comments, please.

Comment thread router/logging.go

clientIP, _, _ := net.SplitHostPort(r.RemoteAddr)
ctxDuration := ctxTime(r.Context())
latency := strconv.FormatInt(int64(ctxDuration), 10)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to stringify ctxDuration, logrus works well with numbers.

Also, this will return the duration in nanoseconds which I see a little bit redundant. I believe millisecond precision should be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants