diff --git a/route/middleHandle.go b/route/middleHandle.go index ace00161d63e446deac135b63c53536a5a804361..7f4ec559fbae7f5754a02eb1c0aac940a7edcb74 100755 --- a/route/middleHandle.go +++ b/route/middleHandle.go @@ -90,7 +90,7 @@ func LoggerHandle(c *gin.Context) { start := time.Now() clientIp := c.ClientIP() method := c.Request.Method - traceId := genTraceId() + traceId := genTraceId(c) reqUri := c.Request.RequestURI c.Set(mycontext.TRACEID, traceId) // diff --git a/route/utils.go b/route/utils.go index 2a736b4bbc32a7328a645ccabc16ed204727bdf2..a6544bd648a7f35f16297bde49b43634829e7bba 100755 --- a/route/utils.go +++ b/route/utils.go @@ -1,11 +1,16 @@ package route import ( + "git.hilo.cn/hilo-common/mycontext" + "github.com/gin-gonic/gin" uuid "github.com/satori/go.uuid" "strings" ) -func genTraceId() string { +func genTraceId(c *gin.Context) string { + if trace := c.GetHeader(mycontext.TRACEID); len(trace) > 0 { + return trace + } traceId := strings.Replace(uuid.NewV4().String(), "-", "", -1) traceId = traceId[:len(traceId)/2] return traceId