From 9ad70b71017ea4c184c0c41a45e0cc027b3d5d51 Mon Sep 17 00:00:00 2001 From: "qiyunfanbo126.com" <815699> Date: Tue, 30 Apr 2024 11:47:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96,=E4=BF=AE=E5=A4=8Dt?= =?UTF-8?q?race?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/middlewares/tracer.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/http/middlewares/tracer.go b/app/http/middlewares/tracer.go index 41beccd..d0158d6 100644 --- a/app/http/middlewares/tracer.go +++ b/app/http/middlewares/tracer.go @@ -1,9 +1,10 @@ package middlewares import ( - "fmt" "github.com/gin-gonic/gin" "qteam/app/http/trace" + "qteam/app/utils" + "strconv" ) const ( @@ -13,22 +14,18 @@ const ( func Trace() gin.HandlerFunc { return func(c *gin.Context) { tracer, err := trace.Tracer() - - fmt.Println(err, "eeee", tracer) - r := c.Request - span := tracer.StartSpan("operation-name") + if err != nil { + utils.Log(c, "trace err", err) + } + span := tracer.StartSpan("base trace") // 可以自定义tag - span.SetName(c.Request.Method + "---" + r.Method) - span.Tag("login", "jaja") + span.SetName(c.Request.RequestURI) + span.Tag("methd", c.Request.Method) c.Request = c.Request.WithContext(c) c.Next() code := c.Writer.Status() - fmt.Println("code", code) - if code >= 400 { - span.SetName(c.Request.RequestURI + "---" + fmt.Sprintf("%s%s", r.Host, r.URL.Path)) - //span.Error(time.Now(), fmt.Sprintf("Error on handling request, statusCode: %d", code)) - } + span.Tag("status", strconv.Itoa(code)) span.Finish() } }