microsoft / ApplicationInsights-node.js

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

App insights customDimension parsing differently locally vs in Azure. #1303

Closed penance316 closed 2 months ago

penance316 commented 2 months ago

Hi team,

I have a small nodeJS project that I am trying to add some customDimension data to, but I have found I am getting different results running locally vs running in Azure functions.

I have a winston logger setup like so:

const logger = createLogger({
    level: isDebug ? 'debug' : 'info',
    defaultMeta: {
      service: serviceName,
    },
    transports: [new transports.Console()],
    format: format.simple(),
  });

And i have the package 'applicationinsights' included in my project something like this:

appInsights
  .setup()
  .setAutoDependencyCorrelation(true)
  .setAutoCollectRequests(true)
  .setAutoCollectPerformance(true, true)
  .setAutoCollectExceptions(true)
  .setAutoCollectDependencies(true)
  .setAutoCollectConsole(true, true)
  .setSendLiveMetrics(false)
  .setDistributedTracingMode(appInsights.DistributedTracingModes.AI);
appInsights.start();

A basic http hook which initalises the applciation insights package then the logger then logs.

require('../services/telemetry');
const logger = require('../helpers/logger').initLogger('HttpHook');
.....

const handler = async function (req, context) {
  const correlationId = uuid.v4();
  logger.setCorrelationId(correlationId);
  logger.info('trigger function received a request.');

  try {
    let bodyData = await req.formData();
    const bodyDataString = Object.fromEntries(bodyData);
.......

When i run this locally with azure core tools the logging in Azure looks correct and seperates out all customDimensions as expected. The message is correctly parsed and the correlationId and service fields are seperated out from the customDimentions. image

But when i run the same code in Azure my logs look like this. The logged message is not really parsed out and instead it is just logged as a string making it hard to query. image

Im assuming something is wrong with my setup, but I'm not sure what as everything seems working correctly when I run it locally Some help/pointer would be appreciated Thanks.

penance316 commented 2 months ago

After some more research, it appears this is probably related to auto instrumentation of the application insights monitor when running in Azure. I have disabled the auto monitoring and am just using the SDK only, and it seems to be working fine. Thanks