Skip to content

Commit

Permalink
Write x-ms-request-id into the abbreviated logging for successful ope…
Browse files Browse the repository at this point in the history
…rations (#694)

Because we may still need to look up these requests in some support situations.
  • Loading branch information
JohnRusk authored and zezha-msft committed Oct 17, 2019
1 parent 5c780fb commit cdd1156
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ste/xferLogPolicy.go
Expand Up @@ -132,6 +132,7 @@ func NewRequestLogPolicyFactory(o RequestLogOptions) pipeline.Factory {
pipeline.WriteRequestWithResponse(b, prepareRequestForLogging(request), response.Response(), err) // only write full headers if debugging or error
} else {
writeRequestAsOneLine(b, prepareRequestForLogging(request))
writeActivityId(b, response.Response())
}

if logBody {
Expand Down Expand Up @@ -183,6 +184,17 @@ func writeRequestAsOneLine(b *bytes.Buffer, request *http.Request) {
fmt.Fprint(b, " "+request.Method+" "+request.URL.String()+"\n")
}

func writeActivityId(b *bytes.Buffer, response *http.Response) {
if response == nil {
return
}
const key = "X-Ms-Request-Id" // use this, rather than client ID, because this one is easier to search by in Service logs
value, ok := response.Header[key]
if ok {
fmt.Fprintf(b, " %s: %+v\n", key, value)
}
}

func prepareRequestForLogging(request pipeline.Request) *http.Request {
req := request
rawQuery := req.URL.RawQuery
Expand Down

0 comments on commit cdd1156

Please sign in to comment.