router icon indicating copy to clipboard operation
router copied to clipboard

Fix Router.match pathAndMethod to only include layers that have methods

Open Gary-Osteen-Q2 opened this issue 4 years ago • 13 comments

Fix #105

Gary-Osteen-Q2 avatar Sep 23 '20 20:09 Gary-Osteen-Q2

@Gary-Osteen-Q2 Thanks for submitting a PR to fix #105. I have reviewed the changes. Just need a collaborator to review now. @niftylettuce do you have time to have a look at this? Let me know if there is anything I missed in my review, I am still new to this 😄

dominicegginton avatar Oct 01 '20 20:10 dominicegginton

Can anyone take some time to look this over?

Gary-Osteen-Q2 avatar Oct 27 '20 17:10 Gary-Osteen-Q2

@niftylettuce: I believe this PR may be required to address this upstream issue: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/222

jmealo avatar Oct 29 '20 21:10 jmealo

@jmealo Thanks! I've always looked forward to giving back to open source eventually. I am elated to think that it might also fix some upstream issues!

Gary-Osteen-Q2 avatar Oct 29 '20 21:10 Gary-Osteen-Q2

Sorry I dropped the ball on this, is this ready to go? Can a few people look over this and ping me back?

niftylettuce avatar Nov 02 '20 13:11 niftylettuce

@niftylettuce it is ready to go from code side. I don't know what else would be needed.

Gary-Osteen-Q2 avatar Nov 02 '20 15:11 Gary-Osteen-Q2

@3imed-jaberi I'm not sure I follow how it would make the update smooth. Logically the layer that gets added to pathOnly have no methods to match in the first place. Whereas pathNotMethod the layer did have a method and it didn't match. Path would then be too generic to me as I would expect others to come in and think that the path matched everything.

Gary-Osteen-Q2 avatar Nov 13 '20 15:11 Gary-Osteen-Q2

We should aim not to break this, which checks the path: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/master/plugins/node/opentelemetry-koa-instrumentation/src

jmealo avatar Nov 13 '20 17:11 jmealo

@jmealo pathOnly is used internally by Router.prototype.match which is a @private method. No outside project should be looking at that variable directly. The ctx.matched gets set at the same place as before in Router.prototype.routes. I don't see how this should affect any other dependent project. Inside Router.prototype.routes the path and ctx.path are unchanged.

Gary-Osteen-Q2 avatar Nov 13 '20 22:11 Gary-Osteen-Q2

@Gary-Osteen-Q2: Sorry for my delayed reply. Your reasoning on a private method is correct in theory, however, the TC39 private methods and getter/setters proposal for JavaScript classes proposal is still a stage 3 draft. Typescript and JSDOC annotations can mark a method as private but JavaScript does not enforce it (yet).

As @3imed-jaberi: pointed out that this PR as implemented would need a MAJOR semver bump because it's an incompatible/breaking change.

I saw an actual monkey patch in the wild that wrapped internal methods of koa-router to set the operation name to the route on outgoing telemetry because there was no way to do it with the public API. npm is full of instrumentation libraries that monkey patch "private" methods.

Instrumentation developers can't really wait/lobby for each upstream projects to change the public API to expose its internals for what they'll consider a niche use case and their users needed better instrumentation yesterday. Since JavaScript doesn't have private methods, we have to tread lightly until there's a TypeScript/ES-Next native ecosystem. Ideally library authors will provide their own instrumentation with time. If that's what you're into you Deno is trying to be that thing.

TLDR: @niftylettuce If we change the path back to pathOnly this is good to go with a PATCH release. If not, this needs to be a MAJOR.

jmealo avatar Mar 22 '21 23:03 jmealo

@JacobMGEvans @Gary-Osteen-Q2 I think it is inferred that path is the same as pathOnly (from naming point of view) - is there any reason other than naming to have it renamed? Or perhaps have both and add the new one and use that internally? I would keep it backwards compatible!

niftylettuce avatar Mar 23 '21 17:03 niftylettuce

@Gary-Osteen-Q2 can you please rebase with the master branch to resolve the conflict and go on here

3imed-jaberi avatar Apr 02 '23 02:04 3imed-jaberi

@Gary-Osteen-Q2 could you please rebase with the latest release main changes, I will take care to ship this fix on your next release whatever major or minor release ;) !

3imed-jaberi avatar Aug 15 '24 15:08 3imed-jaberi