How to use applicationinsights - 10 common examples

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 microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / src / index.ts View on Github external
appId: endpointConfig.appId || process.env.microsoftAppID,
    appPassword: endpointConfig.appPassword || process.env.microsoftAppPassword,
});

// Setup our global error handler
// For production bots use AppInsights, or a production-grade telemetry service to
// log errors and other bot telemetry.
import { TelemetryClient } from "applicationinsights";
// Get AppInsights configuration by service name
const APPINSIGHTS_CONFIGURATION = process.env.APPINSIGHTS_NAME || "";
const appInsightsConfig: IAppInsightsService = botConfig.findServiceByNameOrId(APPINSIGHTS_CONFIGURATION) as IAppInsightsService;
if (!appInsightsConfig) {
    console.log("Please configure your AppInsights connection in your .bot file.");
    process.exit(BOT_CONFIGURATION_ERROR);
}
const telemetryClient = new TelemetryClient(appInsightsConfig.instrumentationKey);

adapter.onTurnError = async (turnContext, error) => {
    // CAUTION:  The sample simply logs the error to the console.
    console.error(error);
    // For production bots, use AppInsights or similar telemetry system.
    // tell the user something happen
    telemetryClient.trackException({ exception: error });
    // for multi-turn dialog interactions,
    // make sure we clear the conversation state
    await turnContext.sendActivity("Sorry, it looks like something went wrong.");
};

// CAUTION: The Memory Storage used here is for local bot debugging only. When the bot
// is restarted, anything stored in memory will be gone.
// const storage = new MemoryStorage();
github CSA-OCP-GER / unicorn / apps / js-calc-backend / app / server.js View on Github external
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");

if (config.instrumentationKey){ 
    appInsights.setup(config.instrumentationKey)
    .setAutoDependencyCorrelation(true)
    .setAutoCollectDependencies(true)
    .setAutoCollectPerformance(true);
    appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-backend-svc";
    appInsights.start();
}
var client = appInsights.defaultClient;

const express = require('express');
const app = express();
const morgan = require('morgan');

const OS = require('os');

// add logging middleware
app.use(morgan('dev'));

// Routes

app.get('/', function(req, res) {
    console.log('received request');
    res.send('Hi!');
});
github denniszielke / phoenix / apps / js-calc-backend / app / server.js View on Github external
require('dotenv-extended').load();
const config = require('./config');
var appInsights = require("applicationinsights");

if (config.instrumentationKey){ 
    appInsights.setup(config.instrumentationKey)
    .setAutoDependencyCorrelation(true)
    .setAutoCollectDependencies(true)
    .setAutoCollectPerformance(true);
    appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "calc-backend-svc";
    appInsights.start();
}
var client = appInsights.defaultClient;

const express = require('express');
const app = express();
const morgan = require('morgan');

const OS = require('os');

// add logging middleware
app.use(morgan('dev'));

// Routes

app.get('/', function(req, res) {
    console.log('received request');
    res.send('Hi!');
});
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 / 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());

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\'';
github Azure / botbuilder-instrumentation / src / index.js View on Github external
var monitor = (bot, options) => {

  options = options || {};

  if ((!options.instrumentationKey) &&
      (!process.env.APPINSIGHTS_INSTRUMENTATIONKEY)){
    throw new Error('App Insights instrumentation key was not provided in options or the environment variable APPINSIGHTS_INSTRUMENTATIONKEY');
  }

  appInsights.setup(options.instrumentationKey || process.env.APPINSIGHTS_INSTRUMENTATIONKEY).start();
  client = appInsights.getClient(options.instrumentationKey || process.env.APPINSIGHTS_INSTRUMENTATIONKEY);

  if (!options.sentimentKey && !process.env.CG_SENTIMENT_KEY) {
    console.warn('No sentiment key was provided - text sentiments will not be collected');
  } else {
    _sentimentKey = options.sentimentKey || process.env.CG_SENTIMENT_KEY;
  }

  var transactions = options.transactions || [];
  setup();

  if (bot) {
    // Adding middleware to intercept all received messages
    bot.use({
        botbuilder: function (session, next) {

            try {
github benc-uk / smilr / node / data-api / controllers / controller.js View on Github external
statusCode = 400;
      title = 'validation-error'
    }

    // Problem Details object as per standard https://tools.ietf.org/html/rfc7807
    let problemDetails = {
      error: true,
      title: title,
      details: err.toString(),
      status: statusCode,
      source: source
    };

    // App Insights
    const appInsights = require("applicationinsights");    
    if(appInsights.defaultClient) appInsights.defaultClient.trackException({exception: err});

    res.status(statusCode).send(problemDetails);
  }    
}
github mauve / vscode-terraform / src / telemetry.ts View on Github external
private createClient() {
    // check if another instance exists
    if (ai.defaultClient) {
      this.client = new ai.TelemetryClient(this.aiKey);
      this.client.channel.setUseDiskRetryCaching(true);
    } else {
      ai.setup(this.aiKey)
        .setAutoCollectConsole(false)
        .setAutoCollectDependencies(false)
        .setAutoCollectExceptions(false)
        .setAutoCollectPerformance(false)
        .setAutoCollectRequests(false)
        .setAutoDependencyCorrelation(false)
        .setUseDiskRetryCaching(true)
        .start();
      this.client = ai.defaultClient;
    }

    this.setCommonProperties();
    this.client.context.tags[this.client.context.keys.sessionId] = vscode.env.sessionId;
    this.client.context.tags[this.client.context.keys.userId] = vscode.env.machineId;
  }
github benc-uk / smilr / node / data-api / lib / utils.js View on Github external
let statusCode = err.code ? err.code : 500;
    if(statusCode < 100 || statusCode > 999) statusCode = 500;

    // Problem Details object as per https://tools.ietf.org/html/rfc7807
    let problemDetails = {
      error: true,
      title: title,
      details: err.toString(),
      status: statusCode,
      source: source
    };

    // App Insights
    const appInsights = require("applicationinsights");    
    if(appInsights.defaultClient) appInsights.defaultClient.trackException({apiError: problemDetails});

    res.status(statusCode).send(problemDetails);
  }