-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(instrumentation-express): Use router path in router span names #2319
feat(instrumentation-express): Use router path in router span names #2319
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2319 +/- ##
==========================================
- Coverage 90.97% 90.75% -0.23%
==========================================
Files 146 156 +10
Lines 7492 7700 +208
Branches 1502 1583 +81
==========================================
+ Hits 6816 6988 +172
- Misses 676 712 +36
|
9d6ddc5
to
90b8471
Compare
plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Outdated
Show resolved
Hide resolved
a42a65f
to
1314d5b
Compare
be86251
to
6804892
Compare
Thank you for your work on this! Overall I like the idea of this and it seems to resolve the issue of span names from basic router usage as I had flagged in the issue, properly renaming What I'm currently stuck on is the nested router use case. The second router span in this PR is rewritten to
|
@JamieDanielson, yes you're right. Thanks for pointing that out.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is titled as a fix, but it could perhaps be considered a feature as it properly implements the router instrumentation 😁 🤷 . I lean toward feature because it is changing span names and is more or less implementing something that didn't properly exist before. What do you think about a title like "feat(instrumentation-express):Use router path in router span names"?
@JamieDanielson we're happy with the rename, feel free to edit. |
router
path from layer stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to hold onto this for a bit longer until this other PR #2408 is merged that fixes the instrumentation of http.get
and changes the output of the ESM spans. It's going to require a few more changes to the ESM tests but they will make more sense now with the client and server spans.
After that PR merges and we update this branch we'll see the ESM tests fail. We'll just need to update the ESM tests here and then this will be good to go 🚀
plugins/node/opentelemetry-instrumentation-express/test/express.test.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-express/test/express.test.ts
Outdated
Show resolved
Hide resolved
I've merged in main and updated the test to use |
The failed tests may be intermittent and unrelated to this. I created #2436 to track but after some re-running they are working. Hope to be able to merge soon! |
Related: getsentry/sentry-javascript#12103
Which problem is this PR solving?
router
spans are falling back to/
as their span name in the current implementation. (Issue: Express instrumentation does not properly handle router usage #1993)requestHandler
spans are not showing the full route in their span name when nested routers are used. (This is not fixing exactly but it is related to fix wrong rpcMetadata.route value when route.use(<middleware>) handle nested router #1613)Short description of the changes
This PR adds a new utility (
getRouterPath
) to recursively search the (possibly nested) parameterised router path when getting the layer metadata. This only affects the span name, not thehttp.route
attribute of the span.http.route
is still showing the mount path. (Active discussion on this: Express instrumentation does not properly handle router usage #1993 (comment))Uses
route
primarily to assign therequestHandler
span name instead oflayerPath
.layerPath
does not represent the full path, only the path of the last matching router when nested routers are used.So if we have a nested router setup like:
The new behaviour is as below:
router - /
router - /api/user/:id
router - /api/user/:id/posts
router - /:postId
requestHandler - /:postId
requestHandler - /api/user/:id/posts/:postId