microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js
MIT License
320 stars 138 forks source link

NodeJS: trackDependency does not store "data" field #1355

Open philippreissing opened 2 days ago

philippreissing commented 2 days ago

I'm trying to use the method trackDependency() to track custom dependencies in a NodeJS backend. I create a custom object and save it like this:

    const message = {
      name: 'query',
      resultCode: error ? error.response.sqlState ?? 'error' : 0,
      data: 'test', //sql.toString().trim(),
      dependencyTypeName: 'Databricks',
      duration: duration,
      success: !error,
    };
    console.log(message);
    appInsights.defaultClient.trackDependency(message); 

Here's how the message looks like (data is hardcoded for testing):

{
  name: 'query',
  resultCode: 0,
  data: 'test',
  dependencyTypeName: 'Databricks',
  duration: 1455.913166999817,
  success: true
}

The event gets saved in log analytics, but the data field always stays empty.

image

I'm using Node JS 18.15.0 with applicationinsights 3.1.0

philippreissing commented 1 day ago

Ok, I found the problem. The library checks if the depency is of SQL type and only then stores the data field. https://github.com/microsoft/ApplicationInsights-node.js/blob/6e0b8d31a2de6c13a05609d0e29a94e62c56d8e0/src/shared/util/util.ts#L100

That feels a bit limiting - why should I not be able to also use the data field in other dependencies?

Anyway, I could solve this by renaming my dependency type to Databricks SQL instead.