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

Add latency in nanoseconds as a response log field #1258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tab1293
Copy link

@tab1293 tab1293 commented Mar 19, 2024

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.

Copy link
Member

@DarthSim DarthSim left a comment

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.

@@ -33,12 +34,15 @@ func LogResponse(reqID string, r *http.Request, status int, err *ierrors.Error,
}

clientIP, _, _ := net.SplitHostPort(r.RemoteAddr)
ctxDuration := ctxTime(r.Context())
latency := strconv.FormatInt(int64(ctxDuration), 10)
Copy link
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.

None yet

2 participants