Skip to content

Commit ac9fee4

Browse files
author
Patrick Bajao
committed
Merge branch 'sh-log-content-length-bytes' into 'master'
Log Content-Length bytes in API response See merge request gitlab-org/gitlab-shell!427
2 parents dc7d87e + 6b05bee commit ac9fee4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

client/client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func testSuccessfulGet(t *testing.T, client *GitlabNetClient) {
9494
require.Equal(t, logrus.InfoLevel, entries[0].Level)
9595
require.Contains(t, entries[0].Message, "method=GET")
9696
require.Contains(t, entries[0].Message, "status=200")
97+
require.Contains(t, entries[0].Message, "content_length_bytes=")
9798
require.Contains(t, entries[0].Message, "Finished HTTP request")
9899
require.Contains(t, entries[0].Message, "correlation_id=")
99100
})
@@ -120,6 +121,7 @@ func testSuccessfulPost(t *testing.T, client *GitlabNetClient) {
120121
require.Equal(t, logrus.InfoLevel, entries[0].Level)
121122
require.Contains(t, entries[0].Message, "method=POST")
122123
require.Contains(t, entries[0].Message, "status=200")
124+
require.Contains(t, entries[0].Message, "content_length_bytes=")
123125
require.Contains(t, entries[0].Message, "Finished HTTP request")
124126
require.Contains(t, entries[0].Message, "correlation_id=")
125127
})

client/gitlabnet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, da
156156
return nil, err
157157
}
158158

159+
if response.ContentLength >= 0 {
160+
logger = logger.WithField("content_length_bytes", response.ContentLength)
161+
}
162+
159163
logger.Info("Finished HTTP request")
160164

161165
return response, nil

0 commit comments

Comments
 (0)