microsoft / ApplicationInsights-node.js

Microsoft Application Insights SDK for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App insights customDimension parsing differently locally vs in Azure.

penance316 opened this issue · comments

commented

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.

commented

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