Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appinsights-logger

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appinsights-logger

thin, yet opinionated wrapper for applcation insights

  • 0.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

AppInsights logger

wrapper for AI setup, compatible with Azure Functions

Install

npm i appinsights-logger --save

Environment setup

Just set ENV variable APPINSIGHTS_INSTRUMENTATIONKEY

Set the AI_MESSAGE_NAMESPACE ENV variable to identify message source. Format is [myCompany].[AgileTeam].[Repo] (foocompany.Architecture.Appinsights)

Usage:

const { trackEvent, trackException } = require('appinsights-logger')

trackEvent({ name: 'TEST', properties: { myProp: 'my value' } })

const ex = new Error('some error')
trackException({ exception: ex, properties: { myProp: 'my value' } })

Advanced usage

HTTP request tracking:

import { markDependency, measureDependency } from 'appinsights-logger'

const marker = markDependency('HTTP', 'GET /products')
try {
  const url = 'https://domain.com/api/products'
  const locations = await requestPromise(url)
  measureDependency(marker, url)
} catch(ex) {
  measureDependency(marker, url, false)
  // could also trackException(ex) here
}

Cosmos query tracking:

dependency tracking is useful for measuring latency of remote calls (SQL, HTTP) and also failures

import { markDependency, measureDependency } from 'appinsights-logger'

const marker = markDependency('cosmos', 'query collection')
try {
  const sql = 'select top 100 from c'
  const locations = await cosmosDb.items.query(sql) // pseudo-code cosmos query
  measureDependency(marker, sql)
} catch(ex) {
  measureDependency(marker, sql, false)
  // could also trackException(ex) here
}

Debug Event tracking

customEvents are powerful because you can query the logs by the customDimensions object

import { trackDebugEvent } from from 'appinsights-logger'

// This 'debug' event will only log if the DEBUG_INSIGHTS="true" env var is set
trackDebugEvent({ name: 'new order',  properties: { order }, measurements: { productCount: order.products.length } }) 
Run E2E Test
cp .env.example .env

fill in .env with App Insight key

npm run build
npm test

FAQs

Package last updated on 01 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc