Skip to content

Commit

Permalink
request_id -> log_id
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed May 6, 2024
1 parent 4b0b483 commit 2bf225e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api_auth_app_access_token_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *AuthService) GetAppAccessToken(ctx context.Context) (*TokenExpire, *Res
return nil, response, NewError("Token", "GetAppAccessToken", resp.Code, resp.Msg)
}

r.cli.Log(ctx, LogLevelDebug, "[lark] Auth#GetAppAccessToken request_id: %s, response: %s", response.RequestID, jsonString(resp))
r.cli.Log(ctx, LogLevelDebug, "[lark] Auth#GetAppAccessToken log_id: %s, response: %s", response.LogID, jsonString(resp))

err = r.cli.store.Set(ctx, genAppTokenKey(r.cli.isISV, r.cli.appID), resp.AppAccessToken, time.Second*time.Duration(resp.Expire))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion api_auth_tenant_access_token_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *AuthService) GetTenantAccessToken(ctx context.Context) (*TokenExpire, *
return nil, response, NewError("Token", "GetTenantAccessToken", resp.Code, resp.Msg)
}

r.cli.Log(ctx, LogLevelDebug, "[lark] Auth#GetTenantAccessToken request_id: %s, response: %s", response.RequestID, jsonString(resp))
r.cli.Log(ctx, LogLevelDebug, "[lark] Auth#GetTenantAccessToken log_id: %s, response: %s", response.LogID, jsonString(resp))

err = r.cli.store.Set(ctx, genTenantTokenKey(r.cli.isISV, r.cli.appID, r.cli.tenantKey), resp.TenantAccessToken, time.Second*time.Duration(resp.Expire))
if err != nil {
Expand Down
18 changes: 11 additions & 7 deletions impl_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ import (
type Response struct {
Method string // request method
URL string // request url
RequestID string // request id, if you got some error and oncall lark/feishu team, please with this request id
LogID string // log id, if you got some error and oncall lark/feishu team, please with this log id
StatusCode int // http response status code
Header http.Header // http response header
ContentLength int64 // http response content length

// deprecated
RequestID string
}

// RawRequest Send a http request of lark
Expand Down Expand Up @@ -78,21 +81,21 @@ func (r *Lark) rawRequest(ctx context.Context, req *RawRequestReq, resp interfac
// 2. do request
response, err = r.doRequest(ctx, rawHttpReq, resp)

requestID, statusCode := getResponseRequestID(response)
logID, statusCode := getResponseLogID(response)
if err != nil {
r.Log(ctx, LogLevelError, "[lark] %s#%s %s %s failed, request_id: %s, status_code: %d, error: %s", req.Scope, req.API, req.Method, req.URL, requestID, statusCode, err)
r.Log(ctx, LogLevelError, "[lark] %s#%s %s %s failed, log_id: %s, status_code: %d, error: %s", req.Scope, req.API, req.Method, req.URL, logID, statusCode, err)
return response, err
}

code, msg, detailErr := getCodeMsg(resp)
if code != 0 {
e := NewError(req.Scope, req.API, code, msg)
e.(*Error).ErrorDetail = detailErr
r.Log(ctx, LogLevelError, "[lark] %s#%s %s %s failed, request_id: %s, status_code: %d, code: %d, msg: %s", req.Scope, req.API, req.Method, req.URL, requestID, statusCode, code, msg)
r.Log(ctx, LogLevelError, "[lark] %s#%s %s %s failed, log_id: %s, status_code: %d, code: %d, msg: %s", req.Scope, req.API, req.Method, req.URL, logID, statusCode, code, msg)
return response, e
}

r.Log(ctx, LogLevelDebug, "[lark] %s#%s success, request_id: %s, status_code: %d, response: %s", req.Scope, req.API, requestID, statusCode, "TODO")
r.Log(ctx, LogLevelDebug, "[lark] %s#%s success, log_id: %s, status_code: %d, response: %s", req.Scope, req.API, logID, statusCode, "TODO")

return response, nil
}
Expand Down Expand Up @@ -179,6 +182,7 @@ func (r *Lark) doRequest(ctx context.Context, rawHttpReq *rawHttpRequest, realRe

response.StatusCode = resp.StatusCode
response.RequestID = resp.Header.Get("X-Request-Id")
response.LogID = resp.Header.Get("x-tt-id")
response.Header = resp.Header
response.ContentLength = resp.ContentLength

Expand Down Expand Up @@ -431,11 +435,11 @@ func getCodeMsg(v interface{}) (code int64, msg string, detail *ErrorDetail) {
return
}

func getResponseRequestID(response *Response) (requestID string, statusCode int) {
func getResponseLogID(response *Response) (logID string, statusCode int) {
if response == nil {
return
}
requestID = response.RequestID
logID = response.LogID
statusCode = response.StatusCode
return
}
Expand Down
4 changes: 2 additions & 2 deletions test/ai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_AI(t *testing.T) {
as.Nil(err)
as.NotNil(resp)
as.Equal("en", strings.ToLower(resp.Language))
as.NotEmpty(response.RequestID)
as.NotEmpty(response.LogID)
})

t.Run("", func(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func Test_AI(t *testing.T) {
as.Nil(err)
as.NotNil(resp)
as.Contains([]string{"country", "national"}, strings.ToLower(resp.Text))
as.NotEmpty(response.RequestID)
as.NotEmpty(response.LogID)
})

t.Run("", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/bitable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_Bitable(t *testing.T) {
TableID: tableID,
})
as.Nil(err)
as.NotEmpty(response.RequestID)
as.NotEmpty(response.LogID)
as.True(len(resp.Items) > 0)
})

Expand Down
2 changes: 1 addition & 1 deletion test/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func Test_EphemeralMessage(t *testing.T) {
as.NotNil(resp)
as.NotEmpty(resp.MessageID)
as.NotNil(res)
as.NotEmpty(res.RequestID)
as.NotEmpty(res.LogID)
}

func Test_BatchSend(t *testing.T) {
Expand Down

0 comments on commit 2bf225e

Please sign in to comment.