The library exposes a function to write directly to an Azure Application Insights from your own application. The example below shows how this can be done using pino-multi-stream.
Example:
const insights = require('pino-applicationinsights')
const pinoms = require('pino-multi-stream')
// create the Azure Application Insights destination stream
const writeStream = await insights.createWriteStream()
// create pino loggger
const logger = pinoms({ streams: [{stream: writeStream }] })
// log some events
logger.info('Informational message')
logger.error(new Error('things got bad'), 'error message')The createWriteStream function creates a writestream that pino-multi-stream can use to send logs to.
Example:
const writeStream = await insights.createWriteStream({
key: 'instrumentationkey'
})Type: String (optional)
The Instrumentation Key of the Azure Application Insights account. If not specified, defaults to APPINSIGHTS_INSTRUMENTATIONKEY environment variable.
Or you could configure Azure Application Insights with your custom preferences by passing setup callback property:
const writeStream = await insights.createWriteStream({
setup: (applicationInsights) =>
applicationInsights
.setup('instrumentationkey')
.setAutoCollectRequests(false)
.setAutoCollectDependencies(false)
.start()
})The only parameter of the callback is the applicationInsights instate to setup and call start on.