7

I have a sample NodeJS application that's trying to log to Azure Application Insights. When I run, app successfully logs to console but Azure App Insights doesn't capture, either when running locally or on hosted Azure App Service. It only captures console.log's output but not of winston. Please advise

Application Log Filesystem is already enabled and set to Debug level on Azure App Service

enter image description here

winston: version 3.3.3

applicationinsights: version 1.8.2

enter image description here

app.js

const http = require('http');
const logger = require('./logger')
const appInsight = require('applicationinsights')

appInsight.setup('<MY INSTRUMENTATION KEY>')
.setAutoDependencyCorrelation(true)
.setAutoCollectRequests(true)
.setAutoCollectPerformance(true, true)
.setAutoCollectExceptions(true)
.setAutoCollectDependencies(true)
.setAutoCollectConsole(true, true)
.setSendLiveMetrics(false)
.setDistributedTracingMode(appInsight.DistributedTracingModes.AI)
.start()
const server = http.createServer((request, response) => {
    console.log('Console can be logged')
    logger.info('Winston info')
    logger.debug('Winston debug')
    logger.error('Winston error')
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello World!");
});

const port = process.env.PORT || 1337;
server.listen(port);
console.log("Server running at http://localhost:%d", port);

logger.js

const winston = require("winston");

const level = process.env.LOG_LEVEL || 'debug';

const logger = winston.createLogger({
    transports: [
        new winston.transports.Console({
            level: level,
            format: winston.format.simple(),
            debugStdout: true,
        })
    ]
});

module.exports = logger
Brian Pham
  • 551
  • 9
  • 23

1 Answers1

8

Turned out that applicationInsights was imported after winston in my demo project

Brian Pham
  • 551
  • 9
  • 23