I used swagger-codegen to generate an express.js application (https://swagger.io/). I have several microservices generated in this fashion, Hence, why apm is so appealing ot me.
When I try to add the apm agent to express microservice (the very first lines in my app.js, nothing is above the code). Here is the code:
// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)
serviceName: 'my_service',
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://apm:8200'
});
Thanks for trying out Elastic APM and for the very detailed bug report - it's highly appreciated
I haven't used Swagger my self, but even though it's "just using Express" it sounds to me like it somehow builds the routes in a way that we can't parse.
Can you share a code snippet of how the microservice routes currently are defined?
I belive that's abstracted away from me. we define routes in a swagger.yaml file, and then we just write functions in like function my_route(req, res, err) {}. They automtacially get called.
I was able to get away with it by manually setting apm.setTransactionName(req.url) .
Ok thanks for checking. Currently custom Swagger support is not on our roadmap. But I'll make sure to keep an eye out for other users requesting this. If so we might want to consider it.
Your fix by calling apm.setTransactionName(req.url) your self might work fine in your case, but there's some hidden traps that I just want to warn you about:
If you have an endpoint that can be called with different HTTP methods (GET, POST, PUT etc). Those will now be joined in the APM UI. I would recommend separating them by calling apm.setTransactionName(req.method + ' ' + req.url) instead
If your URLs contain variable data, e.g. a user ID /user/23123 or a blog post title /posts/learn-how-to-program, it will mean that a lot of different transaction groups are being created. This reduces some of the power of Elastic APM and is not recommended. It would be better to name the transactions for instance GET /user/:id or GET /posts/:title. That way a request for two entities of the same type will still be recognized as the same endpoint and grouped together.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.