SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
448 stars 122 forks source link

gin.Middleware initializes routeMap by gin.Context #51

Closed xuzq3 closed 4 years ago

xuzq3 commented 4 years ago

gin.Middleware has a bug to initialize routeMap by gin.Context and the operationName will be wrong for the next request.

wu-sheng commented 4 years ago

Which library has a bug? go2sky or 3rd party?

xuzq3 commented 4 years ago

Which library has a bug? go2sky or 3rd party?

go2sky/plugins/gin/gin.go

wu-sheng commented 4 years ago

Could you try to submit a pull request to fix it?

arugal commented 4 years ago

Hi @xuzq3 can you provide your code, I can't reproduce this bug :)

xuzq3 commented 4 years ago

go2sky/plugins/gin/gin.go

m.routeMapOnce.Do(func() {
    routes := engine.Routes()
    rm := make(map[string]map[string]routeInfo)
    for _, r := range routes {
        mm := rm[r.Method]
        if mm == nil {
            mm = make(map[string]routeInfo)
            rm[r.Method] = mm
        }
        mm[r.Handler] = routeInfo{
            operationName: c.Request.Host + c.Request.URL.Path,same
        }
        m.routeMap = rm
    }
})

Because of sync.Once, routeMap is initialized by gin.Context of the first request. And it will never change. When the url of the next request is different, operationName is wrong.

arugal commented 4 years ago

haha @xuzq3 are you interested in fixing it :)