We have a node js application and configured application insight using application insight key in launch.json, but in azure application insight showing duplicate log entry, I tried in google and also stackoverflow but unable to solve the issue.
My appInsights.js code is as follows,
const appInsightsObj = require("applicationinsights");
module.exports.initAppInsights = (appInsightKey, appName) => {
appInsightsObj.setup(appInsightKey)
.setAutoDependencyCorrelation(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setUseDiskRetryCaching(true)
.setSendLiveMetrics(true)
.setDistributedTracingMode(appInsightsObj.DistributedTracingModes.AI_AND_W3C);
appInsightsObj.defaultClient.context.tags[appInsightsObj.defaultClient.context.keys.cloudRole] = appName;
appInsightsObj.start();
}
module.exports.trackEvent = (name, properties) => {
const telemetry = appInsightsObj.defaultClient
telemetry.trackEvent({
"name": name,
"properties": properties
})
}
module.exports.insightObj = appInsightsObj;
and log.js file is as follows,
const { appConfig } = require('../../config');
const appInsights = require('./appinsights')
const {AzureApplicationInsightsLogger} = require('winston-azure-application-insights');
const log = require('winston');
require('winston-daily-rotate-file');
const path = require('path')
const _ = require('lodash');
appInsights.initAppInsights(appConfig.get("appinsights_key"), appConfig.get("app_name"));
var transportRotatingFile = new log.transports.DailyRotateFile({
filename: 'loyalty_service_%DATE%.log',
dirname: appConfig.get('logfile_location'),
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transportRotatingFile.on('rotate', function(oldFilename, newFilename) {
// any code while rotating log files.
});
log.add (new AzureApplicationInsightsLogger({client: appInsights.insightObj.defaultClient}))
log.add(new (log.transports.Console)({level: 'info', 'timestamp':true, 'json': false}))
log.add(transportRotatingFile)
module.exports = log;
In launch.json defined the appInsightKey and value and based on that it should read and connect to the application insights.
Azure application insights log entry,
Can anyone suggest me what should be the cause ? and how to resolve the issue.