使用 OpenTracing 规范跟踪请求
trace requests using opentracing specification, Download:
go get -u github.com/gin-contrib/opengintracingSee opentracing/opentracing-go for more information.
For example you have architecture like this
To start requests tracing you have to:
package main
import (
...
"github.com/gin-gonic/gin"
"github.com/gin-contrib/opengintracing"
"github.com/opentracing/opentracing-go"
...
)
var trace = /* setup tracer */
func main() {
...
app := gin.Default()
app.POST("/service1",
opengintracing.NewSpan(trace, "forward to service 1"),
opengintracing.InjectToHeaders(trace, true),
service1handler)
app.POST("/service2",
opengintracing.NewSpan(trace, "forward to service 2"),
opengintracing.InjectToHeaders(trace, true),
service2handler)
...
}package main
import (
...
"github.com/gin-gonic/gin"
"github.com/gin-contrib/opengintracing"
"github.com/opentracing/opentracing-go"
...
)
var trace = /* setup tracer */
func main() {
...
refFunc := opentracing.FollowsFrom
app := gin.Default()
app.POST("",
opengintracing.SpanFromHeaders(trace, "operation", refFunc, true),
// don`t forget to inject if you want continue tracing in other service
opengintracing.InjectToHeaders(trace, true),
handler)
...
}Also don`t forget to forward headers from "Service 1" to "Service 3"
package main
import (
...
"github.com/gin-gonic/gin"
"github.com/gin-contrib/opengintracing"
"github.com/opentracing/opentracing-go"
...
)
var trace = /* setup tracer */
func main() {
...
refFunc := opentracing.ChildOf
app := gin.Default()
app.POST("",
opengintracing.SpanFromHeaders(trace, "operation", refFunc, true),
handler)
...
}暂无开放 Issues,或尚未同步最近议题。