I'm currently testing the NodeJs APM agent. I did a basic integration of the agent in my NestJS API, but the automatic registration request transactions did not work. Therefore, create a custom interceptor to create transactions in each incoming request:
With this implementation I see the requests in kibana.
Now I'm trying to use the query logs in MSSQL (azure), I'm using typeorm, and this uses the mssql (https://www.npmjs.com/package/mssql) and this uses Tedious driver to connect.
From what I understood, the agent of Nodejs automatically logs the queries of Tedious , but I can not see the spans in kibana.
Thanks for trying out the Node.js agent and Elastic APM. You're right that we don't support NestJS directly. But we should automatically pick up the incoming HTTP requests. So without your custom interceptor you should have seen a lot of GET unknown route transactions - did you see that?
If you saw those, it means that we correctly registered the incoming HTTP requests and automatically started and ended transactions for them.
The only thing your custom intercepter then needs to do is give them a more meaningful name than simply GET unknown route. You do that by calling this.apmService.setTransactionName(<name>) (see its documentation here). You shouldn't manually have to start and end a new transaction. In fact I would think this might mess some things up as there already should be an existing transaction.
But regardless, when a transaction is active, you're right that we should automatically pick up MSSQL queries made using the tedious module. I see now that there's a slight typo in our Supported Technologies docs, as it says we only support version ^0.0.5 of Tedious, but I can verify that we do support the entire 2.x range as well.
There's a few reasons why we might not pick them up however. To see exactly what's going on I recommend setting the log level to debug and sending an HTTP request to the app that will trigger an MSSQL query and see what the agent logs. See our Troubleshooting docs for details. If you like, I'd be happy to take a look at the resulting logs.
Follow up: I missed this when reading your message the first time, but I see that you're using import instead of require. And it seems like you're using TypeScript. When you compile the code to JavaScript, this will most likely mess with order of when start() is called on the agent. And this in turn will explain why the Tedious queries are not picked up. See the "Babel / ES Modules support" section in our docs for details on how to fix that.
I uploaded a repository with an example with nestJs that is giving me the same error.
This one does not have Typeorm but it has the same error of the transaction:
no active transaction found - cannot build new span
Thanks for sharing the code. It looks like you're not calling start() on the APM agent until after a lot of the imports have been called. That means that the agent will not have a chance to load before the rest of the app have loaded. And this in turn mean that it cannot add its hooks to get notified about database queries etc.
As far as I could see this project is actually based on Express, which means that we should support automatic naming of transactions. The reason why it's not working is probably the same as described above.
If you move the call to import 'elastic-apm-node/start' up to either be the very first thing in src/main.ts - or maybe even simpler start node with -r elastic-apm-node/start instead of importing elastic-apm-node/start in the source code - that should fix the problem.
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.