MCPcopy
hub / github.com/LyricTian/gin-admin / TraceWithConfig

Function TraceWithConfig

pkg/middleware/trace.go:29–48  ·  view source on GitHub ↗
(config TraceConfig)

Source from the content-addressed store, hash-verified

27}
28
29func 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}

Callers 2

useHTTPMiddlewaresFunction · 0.92
TraceFunction · 0.85

Calls 6

NewTraceIDFunction · 0.92
NewTraceIDFunction · 0.92
AllowedPathPrefixesFunction · 0.85
SkippedPathPrefixesFunction · 0.85
SetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected