增加链路追踪,熟悉的朋友可以将go-admin作为微服务的网关使用😄
This commit is contained in:
1 parent
ccd76445f2
commit
4b5b0507e9
8 files changed
+152
-24
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// Trace 链路追踪
|
||||
func Trace() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
var sp opentracing.Span
|
||||
opName := ctx.Request.URL.Path
|
||||
// Attempt to join a trace by getting trace context from the headers.
|
||||
wireContext, err := opentracing.GlobalTracer().Extract(
|
||||
opentracing.TextMap,
|
||||
opentracing.HTTPHeadersCarrier(ctx.Request.Header))
|
||||
if err != nil {
|
||||
// If for whatever reason we can't join, go ahead an start a new root span.
|
||||
sp = opentracing.StartSpan(opName)
|
||||
} else {
|
||||
sp = opentracing.StartSpan(opName, opentracing.ChildOf(wireContext))
|
||||
}
|
||||
defer sp.Finish()
|
||||
ctx.Next()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user