35 lines
762 B
Go
35 lines
762 B
Go
package middlewares
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"qteam/app/http/trace"
|
|
)
|
|
|
|
const (
|
|
componentIDGOHttpServer = 5004
|
|
)
|
|
|
|
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")
|
|
|
|
// 可以自定义tag
|
|
span.SetName(c.Request.Method + "---" + r.Method)
|
|
span.Tag("login", "jaja")
|
|
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.Finish()
|
|
}
|
|
}
|