Closed
Description
Hello,
I'm facing a weird problem. I'm trying to use the chi
middleware with opentracing, although the middleware injects the span into the request ctx, consequent middlewares are not getting the span.
So in my main, I initiate the tracer as such:
t := opentracer.New(
tracer.WithAgentAddr(net.JoinHostPort(
cfg.DataDogConfig.AgentHost,
cfg.DataDogConfig.TraceAgentPort,
)),
tracer.WithService(cfg.DataDogConfig.Service),
tracer.WithEnv(cfg.DataDogConfig.Env),
tracer.WithServiceVersion(cfg.DataDogConfig.Version),
tracer.WithRuntimeMetrics(),
tracer.WithGlobalTag("commit", commitHash),
)
opentracing.SetGlobalTracer(t)
I add the chi middleware as so
router.Route("/api/v5", func(r chi.Router) {
r.Use(
chitrace.Middleware(chitrace.WithServiceName("http.server")),
....
and in subsequent middlewares I try obtaining the span as so
span := opentracing.SpanFromContext(ctx)
span.SetTag("request_type", v)
But this errors out as span is nil. Seems to be because of using opentracing and chi.middleware together. What am I doing wrong?