Skip to content

Commit

Permalink
CtxTraceID 尝试充gin querystring 或请求json body中获取traceid
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Nov 19, 2020
1 parent 701e8f2 commit 1f6e904
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"

"github.com/gin-gonic/gin"
jsoniter "github.com/json-iterator/go"
"github.com/rs/xid"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -58,6 +59,13 @@ func CtxTraceID(c context.Context) string {
if traceID := gc.GetString(string(TraceIDKeyname)); traceID != "" {
return traceID
}
if traceID := gc.Query(string(TraceIDKeyname)); traceID != "" {
return traceID
}
if traceID := jsoniter.Get(GetGinRequestBody(gc), string(TraceIDKeyname)).ToString(); traceID != "" {
return traceID
}

}
// get from go context
traceIDItf := c.Value(TraceIDKeyname)
Expand Down

0 comments on commit 1f6e904

Please sign in to comment.