microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
324 stars 141 forks source link

auto- dependency collection doesn't work for `fetch` calls? #1104

Open jaked opened 1 year ago

jaked commented 1 year ago

My app has some calls made through the Node http library which are properly tracked as dependencies. But some calls use the Node 18 fetch API, and these aren't tracked. I looked through the AutoCollection code and I don't see anything to monkey-patch this API.

WrongDog commented 1 year ago

same here

cristobal commented 1 year ago

Is this due to the new native fetch implementation rewritten with undici under the hood?

cristobal commented 1 year ago

I tested this at work by creating a request handler that switches between the native fetch and node-fetch, and can also confirm that only the request done with node-fetch are auto collected and those done with native fetch are not collected at all.

As far as i can see the native fetch method (undici under the hood) does not expose any methods or hooks that allows app insights to hook into the calls made by the native fetch, like it does by sniffing http and https requests done via e.g. node-fetch.

An easy alternative is to just stick to and use the node-fetch package for the time being.

BenJohnCarson commented 1 year ago

Seems we're facing the same issue. We just migrated to node 18, removing node-fetch and switching to native fetch and found we've lost dependency tracking. Are there plans to support native fetch with auto collection?

cristobal commented 1 year ago

Seems we're facing the same issue. We just migrated to node 18, removing node-fetch and switching to native fetch and found we've lost dependency tracking. Are there plans to support native fetch with auto collection?

Not sure where this is on the roadmap/timeline of the Application Insights team. We switched to rather use the node-fetch package on our side for all outgoing calls from the node app, and since it uses the underlying http and https libraries from nodejs here ApplicationInsights continues to work as is.

Otherwise you would need to make a custom telemetry provider for Application Inisghts and use a DiagnosticsChannel to track the requests.

Resources:

DaniSchenk commented 1 year ago

Most likely, I'm having the same issue: https://github.com/Azure/azure-sdk-for-js/issues/24505