Skip to content

Commit 86ded9d

Browse files
committed
Auto merge of #3793 - jtgeibel:reduce-log-output, r=pietroalbini
Avoid logging request_id for successful download redirects The request ID is provided to the user in a few error cases to help us locate the log line. However, the ID is not provided to the user for successful requests in general, and in particular for download requests that make up the vast majority of our traffic. Removing this from the logs will save 48 bytes in log traffic per download, and should reduce our log output by about 15%. r? `@pietroalbini`
2 parents bbf47f9 + 2530c37 commit 86ded9d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/middleware/log_request.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,19 @@ impl Display for RequestLine<'_> {
206206
line.add_field("at", at)?;
207207
line.add_field("method", self.req.method())?;
208208
line.add_quoted_field("path", FullPath(self.req))?;
209-
line.add_field("request_id", request_header(self.req, "x-request-id"))?;
209+
210+
// The request_id is not logged for successful download requests
211+
if !(self.req.path().ends_with("/download")
212+
&& self
213+
.res
214+
.as_ref()
215+
.ok()
216+
.map(|ok| ok.status().is_redirection())
217+
== Some(true))
218+
{
219+
line.add_field("request_id", request_header(self.req, "x-request-id"))?;
220+
}
221+
210222
line.add_quoted_field("fwd", request_header(self.req, "x-real-ip"))?;
211223
line.add_field("service", TimeMs(self.response_time))?;
212224
line.add_field("status", status.as_str())?;

0 commit comments

Comments
 (0)