-
Notifications
You must be signed in to change notification settings - Fork 534
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
fix(express): fix wrong rpcMetadata.route value with router.use(<midd… #1615
Conversation
…leware>) handle nested route
My bad, different issue. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1615 +/- ##
=======================================
Coverage 96.06% 96.06%
=======================================
Files 14 14
Lines 914 914
Branches 199 199
=======================================
Hits 878 878
Misses 36 36 |
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 think we should simlify the test setup.
@@ -269,7 +269,7 @@ export class ExpressInstrumentation extends InstrumentationBase< | |||
req.res?.removeListener('finish', onResponseFinish); | |||
span.end(); | |||
} | |||
if (!(req.route && arguments[0] instanceof Error)) { | |||
if (!(req.route && arguments[0] instanceof Error) && layerPath) { |
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.
so we are over pop item right,
If layerPath is undefined, we don't append new record _LAYERS_STORE_PROPERTY. But when next is call, in the current implementation we still pop it.
router.get('/:userId', (req, res) => { | ||
res.status(200).end('user-' + req.params.userId); | ||
}); | ||
router.use(customMiddleware); |
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 customMiddleware layer is the one that make we over remove one layer.
@biuboombiuboom the current implementaion can potential lead to the same issue here right? |
@biuboombiuboom I think we can refactor storeLayerPath to make it more strict on push/pop action. It also prevent instrumentation.ts from knowing of this symbol property. export const storeLayerPath = (request: PatchedRequest, value?: string): {route: string, popLayerPath: () => void} => {
let requestRouteStack: string[]
if (Array.isArray(request[_LAYERS_STORE_PROPERTY]) === false) {
requestRouteStack = [];
Object.defineProperty(request, _LAYERS_STORE_PROPERTY, {
enumerable: false,
value: requestRouteStack,
});
} else {
requestRouteStack = request[_LAYERS_STORE_PROPERTY] as string[]
}
if (value !== undefined) {
requestRouteStack.push(value)
}
const stackLength = requestRouteStack.length
const route = requestRouteStack
.filter(path => path !== '/' && path !== '/*')
.join('');
let alreadyPopStack = false
return {
route,
popLayerPath: () => {
if (value !== undefined) {
return
}
if (requestRouteStack.length === stackLength && alreadyPopStack === false) {
requestRouteStack.pop()
alreadyPopStack = true
} else {
diag.error(
'express instrumentation: pop route stack incorrectly'
);
}
}
}
}; |
greate. |
@biuboombiuboom Let me know when this is ready for review |
What version of OpenTelemetry are you using?
What version of Node are you using?
What did you do?
What did you expect to see?
What did you see instead?