Skip to content

question: opentracing: is the chi middleware compatible with opentracing?  #904

Closed
@KarthikNayak

Description

@KarthikNayak

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions