npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-ai

v0.6.0

Published

Microsoft Azure ApplicationInsights middleware of ExpressJS

Downloads

73

Readme

Build Status npm version Coverage Status

express-ai

The middleware for ExpressJS that enables developers to use Microsoft Azure Application Insights

Installation

npm install express-ai@latest

Supported versions of Node.js:

  • Latest
  • 8.X
  • 7.X
  • 6.X
  • 5.X
  • 4.X

Usage

Express-AI logs the request information as well as the errors that happened during the handling of a request.

In order to use express-ai, you should do the following ( inside your app.js or wherever you apply middlewares ):

var ai = require('express-ai').loggers(app, 'YOUR_INSTRUMENTATION_KEY', true); // >= 0.3.X
// var ai = require('express-ai')(app, 'YOUR_INSTRUMENTATION_KEY', true); // < 0.2.8
...
app.use(ai.logRequest);
...
app.use(ai.logErrors);

This setup logs every request and every unhandled exception that happens during the processing of request. The last parameter in the first line is disabline AI autocollection feature. In order to use custom logging inside of you route handler, you need to do the following:

res.locals.log.trackEvent('test', {
    val: 'my extra-important value',
    requestId: res.locals.requestId
  });

Keep in mind that requestId is not required, it is provided as a convenience to correlate logs for request.

Logging can also be done outside the context of HTTP Request. In that case please use the app.locals.log object, as in the following examples:

var app = require('../app');
...
var server = http.createServer(app);
...
server.on('error', onError);
server.on('listening', onListening);

function onError(error) {

  app.locals.log.traceError(error, 'Error while starting application');
  ...
}

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  app.locals.log.traceInfo('Listening started', { port: bind});
}

Custom Logging API

For custom logging purposes, the res.locals.log object exposes the following functions:

traceInfo(message: string, properties?: {[key: string]: string}): void;
traceError(error: Error, message: string, properties?: {[key: string]: string}): void;
traceWarning(message: string, properties?: {[key: string]: string}): void;
traceVerbose(message: string, properties?: {[key: string]: string}): void;
traceCritical(message: string, properties?: {[key: string]: string});

trackEvent(name: string, properties?: {[key: string]: string}): void;
trackMetric(name: string, value: number): void;
trackRequest(req: express.Request, res: express.Response): void

Version history

  • 0.1 - basic / development functionality
  • 0.2 - production ready, not yet fully tested
  • 0.3 - fully tested, supports only newest version of Node
  • 0.4 - support for all versions of Node >= 0.10

Plans

  1. ~~Extend custom logging~~ (done as of 0.2.X)
  2. ~~Support custom metrics~~ (done as of 0.2.X)
  3. ~~Handle non-request related events (start of application / stop / crash)~~ (done as of 0.2.X)
  4. ~~Tests with AppService~~ (it powers my blog - blog.developin.cloud, some problems already found and fixed, as of 0.2.4 )
  5. ~~Unit Tests~~ (done as of 0.3.X)
  6. (Further) API improvements
  7. Performance tests (memory footprint)
  8. Prepare for 1.0 release :)