(config TraceConfig)
| 27 | } |
| 28 | |
| 29 | func TraceWithConfig(config TraceConfig) gin.HandlerFunc { |
| 30 | return func(c *gin.Context) { |
| 31 | if !AllowedPathPrefixes(c, config.AllowedPathPrefixes...) || |
| 32 | SkippedPathPrefixes(c, config.SkippedPathPrefixes...) { |
| 33 | c.Next() |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | traceID := c.GetHeader(config.RequestHeaderKey) |
| 38 | if traceID == "" { |
| 39 | traceID = fmt.Sprintf("TRACE-%s", strings.ToUpper(xid.New().String())) |
| 40 | } |
| 41 | |
| 42 | ctx := util.NewTraceID(c.Request.Context(), traceID) |
| 43 | ctx = logging.NewTraceID(ctx, traceID) |
| 44 | c.Request = c.Request.WithContext(ctx) |
| 45 | c.Writer.Header().Set(config.ResponseTraceKey, traceID) |
| 46 | c.Next() |
| 47 | } |
| 48 | } |
no test coverage detected