opentracing-contrib / javascript-express

OpenTracing middleware for express
Apache License 2.0
39 stars 20 forks source link

Question: Incorrect span operation name #13

Open sachdevm opened 5 years ago

sachdevm commented 5 years ago

(Disclaimer: I am fairly new to Node.js and express so please pardon me if I am missing something silly here).

I am going through the book "Practical Node.js" and tried to inject the express middleware in this example.

I am using a Jaeger client and injected the middleware like this.

The app has two operations: "/" and "/users". However, when I look at the spans in Jaeger, the span operation name is set to "/" for both cases. Jaeger screenshot

The issue is that while the http.url is correctly set to "/users", the span operation name is set to "/". On debugging the code, I found that the span is set correctly when the request is first intercepted but reset to "/" in the "finishSpan" function here.

From what I can understand, this seems related to how the author has setup the users route.

So the question is whether the route setup is some sort of anti-pattern or is there a way to "hint" the middleware to not fix the operation name?

obscurerichard commented 4 years ago

I ran into this as well - and I'm not sure that it really is a bug, but a reflection of one of the limitations of the way Express routes work.

It is desirable to make the operation the route and not the full path, since the full path might have IDs that are variable in it. But it would be nice to get the entire route path... but the req.route object does not have that stack of routes available.

Maybe you would have to monkeypatch the Express app route() function to keep a stack of the routes applied to a request and then unwind that to build a full route path in finishSpan()?