Microsoft Application Insights SDK for Node.js
Перейти к файлу
Luke Hoban 0cf4b346bd Refactor the dependency on ai.js for better typing
Adds a fixed ai.d.ts which describes the API that the
generated ai.js next to it will actually expose.

TypeScript will use this .d.ts to infer the type information
correctly in `import ai = require("./ai")`.

Also fix up a couple of latent bugs that were found once type
checking kicks in against ai.d.ts.
2015-01-09 17:19:11 -08:00
Scripts/typings Refactor the dependency on ai.js for better typing 2015-01-09 17:19:11 -08:00
Tests Test cleanup 2014-11-26 14:06:20 -08:00
.gitignore Refactor the dependency on ai.js for better typing 2015-01-09 17:19:11 -08:00
.npmignore Incorporate typescript build into the package.json 2015-01-09 16:20:59 -08:00
ExampleUsage.ts add cookies for user/session context 2014-11-25 18:50:37 -08:00
License.txt change to MIT license 2014-08-05 13:14:17 -07:00
Node.njsproj Refactor the dependency on ai.js for better typing 2015-01-09 17:19:11 -08:00
README.md fix typo in readme 2014-12-11 22:28:28 -08:00
Sender.ts Incorporate typescript build into the package.json 2015-01-09 16:20:59 -08:00
ai.d.ts Refactor the dependency on ai.js for better typing 2015-01-09 17:19:11 -08:00
ai_stub.js refactor the node/browser extension model to use inheritance 2014-11-17 14:02:17 -08:00
applicationInsights.ts Refactor the dependency on ai.js for better typing 2015-01-09 17:19:11 -08:00
install.js refactor the node/browser extension model to use inheritance 2014-11-17 14:02:17 -08:00
package.json Incorporate typescript build into the package.json 2015-01-09 16:20:59 -08:00

README.md

Application Insights for Node.js

NPM version

Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

-- nodejs.org

This project extends the Application Insights API surface to support Node.js. Application Insights is a service that allows developers to keep their application available, performing and succeeding. This node module will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal.

Requirements

Install

    npm install applicationinsights

Get an instrumentation key

Note: an instrumentation key is required before any data can be sent. Please see the "Getting an Application Insights Instrumentation Key" section of the wiki for more information. To try the SDK without an instrumentation key, set the instrumentationKey config value to a non-empty string.

Usage

Configuration

import aiModule = require("applicationInsights");

var appInsights = new aiModule.NodeAppInsights({
	instrumentationKey: "<guid>" // see "Requirements" section to get a key
});

Track events/metrics/traces/exceptions

appInsights.trackTrace("example trace");
appInsights.trackEvent("example event");
appInsights.trackException(new Error("example error"), "handledAt");
appInsights.trackMetric("example metric", 1);

Track all http.Server requests

// wraps http.Server to inject request tracking
appInsights.trackAllHttpServerRequests();

var port = process.env.port || 0;
var server = http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(port);

Track uncaught exceptions

// listens for process.on("uncaughtException", ...);
// when an exception is thrown, calls trackException and re-throws the Error.
appInsights.trackAllUncaughtExceptions();

Contributing

Development environment

npm install node-mocks-http
npm install async
  • (optional) Set an environment variable to your instrumentation key
set APPINSIGHTS_INSTRUMENTATION_KEY=<insert_your_instrumentation_key_here>
  • Run tests
node Tests\TestServer.js

Note: the startup file can also be changed to TestServer.js in the *.njsproj so that the IDE runs tests instead of the example server.

    <StartupFile>Tests\TestServer.js</StartupFile>
    <!-- <StartupFile>ExampleUsage.js</StartupFile> -->

How to integrate with Azure

  1. Click on your website tile and scroll down to the Console tile. Type the command (as shown above) to install the module from the Node Package Manager.

  2. Scroll to the bottom of your website blade to the Extensions tile. Click the Add button and select Visual Studio Online and add the extension. You may need to refresh the current blade for it to appear on your list of extensions.

  3. Next, scroll to the top and in the Summary tile, click on the section that says Application Insights. Find your Node website in the list and click on it. Then click on the Properties tile and copy your instrumentation key.

  4. From the website blade click "site settings". Under the "App settings" section, enter a new key "APPINSIGHTS_INSTRUMENTATION_KEY" and paste your instrumentation key into the value field.

  5. Go back to your Extensions tile and click on Visual Studio Online to open up the VSO blade. Click the Browse button to open VSO to edit your files.

  6. Once you open VSO, click on the server.js file and enter the require statement as stated above.

  7. Open your website and click on a link to generate a request.

  8. Return to your project tile in the Azure Portal. You can view your requests in the Monitoring tile.