0cf4b346bd
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. |
||
---|---|---|
Scripts/typings | ||
Tests | ||
.gitignore | ||
.npmignore | ||
ExampleUsage.ts | ||
License.txt | ||
Node.njsproj | ||
README.md | ||
Sender.ts | ||
ai.d.ts | ||
ai_stub.js | ||
applicationInsights.ts | ||
install.js | ||
package.json |
README.md
Application Insights for Node.js
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
- Install Visual Studio
- Install Node.js tools for Visual Studio
- Install git tools for windows
- Install Node.js
- Install test dependencies
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
-
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.
-
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.
-
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.
-
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.
-
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.
-
Once you open VSO, click on the
server.js
file and enter the require statement as stated above.
-
Open your website and click on a link to generate a request.
-
Return to your project tile in the Azure Portal. You can view your requests in the Monitoring tile.