feat: 新增logid

This commit is contained in:
余泓铮
2025-07-15 20:18:40 +08:00
parent 429479d3a3
commit b598c162a9

View File

@@ -14,6 +14,7 @@ import (
"strings"
"time"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
@@ -233,6 +234,7 @@ func (s *DriverSession) RequestWithRetry(method string, urlStr string, rawBody [
func (s *DriverSession) Request(method string, urlStr string, rawBody []byte, opts ...option.ActionOption) (
rawResp DriverRawResponse, err error,
) {
logid := uuid.New().String()
timeout := s.timeout
options := option.NewActionOptions(opts...)
if options.Timeout > 0 {
@@ -264,7 +266,7 @@ func (s *DriverSession) Request(method string, urlStr string, rawBody []byte, op
logger = log.Debug().Bool("success", true)
}
logger = logger.Str("request_method", method).Str("request_url", rawURL).
logger = logger.Str("logid", logid).Str("request_method", method).Str("request_url", rawURL).
Str("request_body", string(rawBody))
if !driverResult.RequestTime.IsZero() {
logger = logger.Int64("request_time", driverResult.RequestTime.UnixMilli())
@@ -287,6 +289,8 @@ func (s *DriverSession) Request(method string, urlStr string, rawBody []byte, op
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-HTTP-Request-ID", logid)
req.Header.Set("logid", logid)
driverResult.RequestTime = time.Now()
var resp *http.Response