ApplicationInsights-node.js icon indicating copy to clipboard operation
ApplicationInsights-node.js copied to clipboard

Dependency requests not logged on node 20

Open arisewanggithub opened this issue 4 months ago • 5 comments

We upgraded to node 20 and find that requests telemetry work but dependency telemetry is not logged (with latest version 2.9.5. or with an old version 2.5.2). With node 18, it works well. Is it by design that node 20 and above won't work with appInsights?

arisewanggithub avatar Mar 06 '24 00:03 arisewanggithub

@arisewanggithub Some further information would be helpful here. Can you provide the package.json for the application you're instrumenting and taking a look at the code where you expect dependency telemetry to be generated would be helpful too.

JacksonWeber avatar Mar 06 '24 01:03 JacksonWeber

@JacksonWeber, I've sent you the package.json in private. Please let me know if you need anything else to troubleshoot.

arisewanggithub avatar Mar 06 '24 03:03 arisewanggithub

@arisewanggithub I'm sorry, but I'm not quite sure where you sent the package.json. What method did you use to send it to me?

JacksonWeber avatar Mar 06 '24 23:03 JacksonWeber

@JacksonWeber , I sent the files to your corp email. I also pinged you on teams. Please let me know if you didn't receive it.

arisewanggithub avatar Mar 07 '24 00:03 arisewanggithub

Works fine here with Node 20 and Fastify, not sure if you had the same problem that we had, however we needed todo some changes to our code after upgrading the application insights package. Since it suddenly stopped tracking the http requests to our server application.

Old code:

const app = fastify(fastifyOptions);
...
configureApplicationInsights();

New Code:

configureApplicationInsights();

const app = fastify(fastifyOptions);
...

The issue at hand

One needs to initialize and start the application insights client before the server is initialized, otherwise it seems that the http.createServer wrapper created here will not be initialized and not be able to intercept the incoming requests to the server.

Seems like the changes in the code happened about 6 months ago.

cristobal avatar Mar 13 '24 13:03 cristobal

@cristobal , thanks for the reply. But that doesn't look like to be the cause of my issue. Also, in my case, request telemetry works. What is broken is dependency telemetry. And for the change you quoted, it's for request telemetry, not for dependency telemetry. So, it should be irrelevant, IMHO. Our code is using React. And we use the fetch API to send dependency requests.

arisewanggithub avatar Mar 14 '24 20:03 arisewanggithub

Closing this issue as auto instrumentation of the fetch API is not supported. Thank you for your report.

JacksonWeber avatar Mar 14 '24 23:03 JacksonWeber

A summary of what happened. From node 18, node.js has a native implementation of the fetch API. In node 16, node-fetch was used and app insights still supports it. But app insights doesn't support this native implementation of the fetch API. And in node 18, the native fetch is used by default. That's why the Dependency telemetry breaks. A workaround is to force to use node-fetch in node 18.

arisewanggithub avatar Mar 20 '24 18:03 arisewanggithub