Opentracing middleware for Gear.
package main
import (
"time"
"github.com/opentracing/basictracer-go"
"github.com/opentracing/opentracing-go"
"github.com/teambition/gear"
"github.com/teambition/gear-tracing"
)
func init() {
opentracing.SetGlobalTracer(basictracer.New(basictracer.NewInMemoryRecorder()))
// use zipkin tracer
// collector, err := zipkintracer.NewScribeCollector("127.0.0.1:9410", 3*time.Second)
// if err == nil {
// tracer, err := zipkintracer.NewTracer(zipkintracer.NewRecorder(collector, false, "https://github.com", "gear-tracing"))
// if err == nil {
// opentracing.SetGlobalTracer(tracer)
// }
// }
}
func main() {
app := gear.New()
router := gear.NewRouter()
router.Use(tracing.New())
router.Get("/", func(ctx *gear.Context) error {
span := opentracing.SpanFromContext(ctx)
assert.NotNil(span)
span.SetTag("testing", "testing")
return ctx.HTML(200, "Test Tracing")
})
app.UseHandler(router)
app.Listen(":3000")
}