初始化,修复trace
This commit is contained in:
parent
8cee5f1f2f
commit
9ad70b7101
|
@ -1,9 +1,10 @@
|
||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"qteam/app/http/trace"
|
"qteam/app/http/trace"
|
||||||
|
"qteam/app/utils"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,22 +14,18 @@ const (
|
||||||
func Trace() gin.HandlerFunc {
|
func Trace() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
tracer, err := trace.Tracer()
|
tracer, err := trace.Tracer()
|
||||||
|
if err != nil {
|
||||||
fmt.Println(err, "eeee", tracer)
|
utils.Log(c, "trace err", err)
|
||||||
r := c.Request
|
}
|
||||||
span := tracer.StartSpan("operation-name")
|
span := tracer.StartSpan("base trace")
|
||||||
|
|
||||||
// 可以自定义tag
|
// 可以自定义tag
|
||||||
span.SetName(c.Request.Method + "---" + r.Method)
|
span.SetName(c.Request.RequestURI)
|
||||||
span.Tag("login", "jaja")
|
span.Tag("methd", c.Request.Method)
|
||||||
c.Request = c.Request.WithContext(c)
|
c.Request = c.Request.WithContext(c)
|
||||||
c.Next()
|
c.Next()
|
||||||
code := c.Writer.Status()
|
code := c.Writer.Status()
|
||||||
fmt.Println("code", code)
|
span.Tag("status", strconv.Itoa(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.Finish()
|
span.Finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue