How to use the applicationinsights.setup function in applicationinsights

To help you get started, we’ve selected a few applicationinsights examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benc-uk / smilr / node / data-api / server.js View on Github external
const cors = require('cors');
const ExpressSwaggerGenerator = require('express-swagger-generator')

const databaseConnection = require('./core/database');
const apiRoutes = require('./core/routes');

// Load .env file if it exists
require('dotenv').config()

// Disable all console output when testing
if(process.env.NODE_ENV == 'test') console.log = function() {}

// App Insights. Set APPINSIGHTS_INSTRUMENTATIONKEY as App Setting or env var
if(process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
  const appInsights = require("applicationinsights");
  appInsights.setup()
  .setAutoDependencyCorrelation(true)
  .setAutoCollectRequests(true)
  .setAutoCollectPerformance(true)
  .setAutoCollectExceptions(true)
  .setAutoCollectDependencies(true)
  .setAutoCollectConsole(true, true)
  .setUseDiskRetryCaching(true);
  appInsights.start();
  console.log("### Server will report data to App Insights");
}

// Create express app
console.log(`### API service starting...`);
const app = express();

// Allow all CORS and parse any JSON we receive
github microsoft / BotBuilder-Samples / Node / core-AppInsights / app.js View on Github external
// This loads the environment variables from the .env file
require('dotenv-extended').load();

var builder = require('botbuilder');
var restify = require('restify');

var telemetryModule = require('./telemetry-module.js');

var appInsights = require('applicationinsights');
appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATION_KEY).start();
var appInsightsClient = new appInsights.TelemetryClient();

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log('%s listening to %s', server.name, server.url);
});

// Create connector and listen for messages
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

server.post('/api/messages', connector.listen());
github microsoft / BotFramework-Emulator / packages / app / main / src / telemetry / telemetryService.ts View on Github external
private static startup(): void {
    if (!this._hasStarted) {
      AppInsights.setup(INSTRUMENTATION_KEY)
        // turn off extra instrumentation
        .setAutoCollectConsole(false)
        .setAutoCollectDependencies(false)
        .setAutoCollectExceptions(false)
        .setAutoCollectPerformance(false)
        .setAutoCollectRequests(false)
        // Fix for zonejs / restify conflict (https://github.com/Microsoft/ApplicationInsights-node.js/issues/460)
        .setAutoDependencyCorrelation(false);
      // do not collect the user's machine name
      AppInsights.defaultClient.context.tags[AppInsights.defaultClient.context.keys.cloudRoleInstance] = '';
      AppInsights.start();

      this._client = AppInsights.defaultClient;
      this._hasStarted = true;
    }
  }
github forcedotcom / salesforcedx-vscode / packages / salesforcedx-vscode-core / src / telemetry / telemetryReporter.ts View on Github external
private createAppInsightsClient(key: string) {
    // check if another instance is already initialized
    if (appInsights.defaultClient) {
      this.appInsightsClient = new appInsights.TelemetryClient(key);
      // no other way to enable offline mode
      this.appInsightsClient.channel.setUseDiskRetryCaching(true);
    } else {
      appInsights
        .setup(key)
        .setAutoCollectRequests(false)
        .setAutoCollectPerformance(false)
        .setAutoCollectExceptions(false)
        .setAutoCollectDependencies(false)
        .setAutoDependencyCorrelation(false)
        .setAutoCollectConsole(false)
        .setUseDiskRetryCaching(true)
        .start();
      this.appInsightsClient = appInsights.defaultClient;
    }

    this.appInsightsClient.commonProperties = this.getCommonProperties();
    if (this.uniqueUserMetrics && vscode && vscode.env) {
      this.appInsightsClient.context.tags['ai.user.id'] = vscode.env.machineId;
      this.appInsightsClient.context.tags['ai.session.id'] =
github nzthiago / BotInsightsTests / Node / bot.js View on Github external
function create(connector) {
    
    appInsights.setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY).start();
    var appInsightsClient = appInsights.getClient();

    var HelpMessage = '\n * If you want to know which city I\'m using for my searches type \'current city\'. \n * Want to change the current city? Type \'change city to cityName\'. \n * Want to change it just for your searches? Type \'change my city to cityName\'';
    var UserNameKey = 'UserName';
    var UserWelcomedKey = 'UserWelcomed';
    var CityKey = 'City';

    // Setup bot with default dialog
    var bot = new builder.UniversalBot(connector, function (session) {

        var telemetry = telemetryModule.createTelemetry(session, { setDefault: false });

        // initialize with default city
        if (!session.conversationData[CityKey]) {
            session.conversationData[CityKey] = 'Seattle';
github DFEAGILEDEVOPS / MTC / admin / helpers / app-insights.js View on Github external
const startInsightsIfConfigured = async () => {
  if (config.Monitoring.ApplicationInsights.Key) {
    console.log('initialising application insights module')
    appInsights.setup()
      .setAutoDependencyCorrelation(true)
      .setAutoCollectRequests(true)
      .setAutoCollectPerformance(true)
      .setAutoCollectExceptions(config.Monitoring.ApplicationInsights.CollectExceptions)
      .setAutoCollectDependencies(config.Monitoring.ApplicationInsights.CollectDependencies)
      .setAutoCollectConsole(false)
      .setUseDiskRetryCaching(true)
      .start()

    let buildNumber
    try {
      buildNumber = await getBuildNumber()
    } catch (error) {
      buildNumber = 'NOT FOUND'
    }
    appInsights.defaultClient.commonProperties = {
github anastasiia-zolochevska / signaling-server / server.js View on Github external
var express = require('express');
var bodyParser = require('body-parser');
var helmet = require('helmet');
var cors = require('cors');
var http = require('http');
process.env.APPINSIGHTS_INSTRUMENTATIONKEY = process.env.APPINSIGHTS_INSTRUMENTATIONKEY || "NO_APPLICATION_INSIGHTS";
appInsights = require("applicationinsights");
appInsights.setup().setAutoCollectExceptions(true)

var clientCounter = 1;
var clientToId = {};
var peers = {};
var connectionsToClean = new Set();

var port = process.env.PORT || 3000;
var allowedOrigins = (process.env.CORS_ORIGINS || '*').split(',')
var intervalToCleanConnections = process.env.INTERVAL || 10000;

if (process.env.ENABLE_LOGGING_TO_FILE){
    const fs = require('fs')
    var logLocation = process.env.LOGGING_FILE_LOCATION || 'D:\home\site\wwwroot\api.access.log'
    var access = fs.createWriteStream(logLocation + new Date().getMilliseconds());

    process.stdout.write = process.stderr.write = access.write.bind(access);
github bradygaster-zz / azure-tools-vscode / src / telemetry.js View on Github external
function newTelemetryClient() {
    telemetryClient = appInsights
        .setup(constants.telemetryKey)
        .setAutoDependencyCorrelation(false)
        .setAutoCollectRequests(false)
        .setAutoCollectPerformance(false)
        .setAutoCollectExceptions(false)
        .setAutoCollectDependencies(false)
        .setAutoCollectConsole(false)
        .start()
        .client;

    telemetryClient.addTelemetryProcessor((envelope, context) => {
        if (envelope.iKey == constants.telemetryKey
            && envelope.data.baseType == "EventData") {
            return true;
        }
        return false;
github DFEAGILEDEVOPS / MTC / pupil-api / src / helpers / app-insights.ts View on Github external
startInsightsIfConfigured: async () => {
    if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
      appInsights.setup()
        .setAutoDependencyCorrelation(true)
        .setAutoCollectRequests(true)
        .setAutoCollectPerformance(true)
        .setAutoCollectExceptions(false)
        .setAutoCollectDependencies(true)
        .setAutoCollectConsole(false)
        .setUseDiskRetryCaching(true)
        .start()

      let buildNumber
      try {
        buildNumber = await PingController.getBuildNumber()
      } catch (error) {
        buildNumber = 'NOT FOUND'
      }
      appInsights.defaultClient.commonProperties = {