Comments (3)
I have a feeling there will not be a clean solution to this.
Option 1: Try to resolve out all the paths inside the express.Routers
from the req.app._router.stack
array. Have looked into this a little - seems to get messy, fast!
Below is just pseudo-code for what that might look like:
const getRoutesOfLayer = (layer, path = '') => {
if (layer && layer.route && layer.route.path && layer.regexp) {
layer.route.path = path + layer.route.path;
return [layer];
}
if (layer && layer.name === 'router' && layer.handle && layer.handle.stack && layer.path) {
return layer.handle.stack.reduce((acc, routerLayer) => {
return [
...acc,
...getRoutesOfLayer(routerLayer, path + layer.path),
];
}, []);
}
return [];
};
matchedRouteMiddleware = req.app._router.stack
.reduce((acc, layer) => {
return [
...acc,
...getRoutesOfLayer(layer),
];
}, [])
.filter((middleware) => {
// Check if the URL matches the route
const isMatch = middleware.regexp.test(preQueryUrl);
// Add matches in the hope that common routes will be faster than searching everything
if (isMatch) { commonRouteMiddlewares.push(middleware); }
return isMatch;
})[0];
Option 2: Ditch the whole idea of express middleware and instead extend the express.Route.prototype.dispatch
prototype.
Again, the below is just pseudo-code for what that might look like:
const defaultImplementation = express.Route.prototype.dispatch;
express.Route.prototype.dispatch = function handle(req, res, next) {
// req.route.path is now available
handler(req, res);
defaultImplementation.call(this, req, res, next);
};
^ To note - although the handler now has access to req.route.path
, it does not include the path of the express.Router
that it might sit under.
Not imagining this is going to be a fast fix - but keen to be kept in the loop!
from scout_apm_node.
Hi @provinceinnovation thanks for reporting this -- the path will be more likely the second option, with some tracking if necessary to get the routes' path if needed.
from scout_apm_node.
Hey @provinceinnovation so I got a chance to look at this and realized that what's happening is that the request is getting captured (I see requests being sent to core-agent
) but they're not marked up with the path
and url
tags that they should be, so the request is actually being ignored there (we ignore any path that we can't determine a url/path for).
As you surmised (I think) the problem is that the URL can't be determined from the router, but the approach I'm taking is shimming the router itself (much like your second option) -- I'll be either Router#handle
or Router#[HTTP verb]
if I can't get everything I'd need from handle
.
from scout_apm_node.
Related Issues (20)
- Unclear procedure/documentation around setup
- Default to TCP socket for core agent communications
- scout.install Promise never resolves HOT 6
- Update core agent version to 1.3.0
- Memory leak HOT 4
- Remove event listeners upon shutdown?
- Express v5 support and failure-proofing
- Significant RAM and CPU impact HOT 5
- More intuitive default logger with level filtering
- Sudden exits on Mac OSX
- Bad/Invalid endpoint name in Controller logs
- Add documentation for clustered deployments HOT 1
- Incorrect check if agent is running on a TCP socket HOT 2
- [NestJS] Stopping undefined span HOT 4
- Add custom provider for nest integration
- How do I import when using Typescript? HOT 5
- Investigate monitoring of PostgreSQL queries when using Sequelize
- TypeError: this.logFn is not a function HOT 5
- Sending additional information for background jobs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scout_apm_node.