Add trace log with successful HTTP response data

This commit is contained in:
Tulir Asokan 2023-09-05 00:34:51 +03:00
parent 52a703c94d
commit 75468e87d8

View file

@ -97,5 +97,16 @@ func typedHTTPResponse[T proto.Message](resp *http.Response, err error) (parsed
}
parsed = parsed.ProtoReflect().New().Interface().(T)
retErr = decodeProtoResp(body, resp.Header.Get("Content-Type"), parsed)
successEvt := zerolog.Ctx(resp.Request.Context()).Trace()
if successEvt.Enabled() {
successEvt.
Int("status_code", resp.StatusCode).
Str("url", resp.Request.URL.String()).
Str("response_body", base64.StdEncoding.EncodeToString(body)).
Bool("parsed_has_unknown_fields", len(parsed.ProtoReflect().GetUnknown()) > 0).
Type("parsed_data_type", parsed).
Any("parsed_data", parsed).
Msg("HTTP request to Google Messages succeeded")
}
return
}