初始化,修复trace
This commit is contained in:
		
							parent
							
								
									8cee5f1f2f
								
							
						
					
					
						commit
						9ad70b7101
					
				|  | @ -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() | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue