How to use the applicationinsights.defaultClient 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 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 / 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);
  }
github Azure / kubernetes-hackfest / app-experimental / cache-api / app.js View on Github external
app.use(function(req, res, next) {
  /* AppInsights request tracking for GET and POST */
  if (req.method === 'GET' || req.method === 'POST') {
    appInsights.defaultClient.trackNodeHttpRequest({
      request: req,
      response: res
    });
  }

  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader(
    'Access-Control-Allow-Methods',
    'GET, POST, OPTIONS, PUT, PATCH, DELETE'
  );
  res.setHeader(
    'Access-Control-Allow-Headers',
    'X-Requested-With,content-type'
  );
  next();
});
github benc-uk / nodejs-demoapp / src / todo / utils.js View on Github external
sendData(res, data) {
    // App Insights
    const appInsights = require("applicationinsights");    
    if(appInsights.defaultClient) appInsights.defaultClient.trackEvent({name: "dataEvent", properties: {data: JSON.stringify(data)}});
    
    res.status(200).send(data)
    return;    
  }
}
github denniszielke / phoenix / apps / js-calc-frontend / 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-frontend";
    appInsights.start();
}
var client = appInsights.defaultClient;

const express = require('express');
const app = express();
const morgan = require('morgan');
const request = require('request');
const OS = require('os');
const redis = require("redis");

var redisClient = null;

var publicDir = require('path').join(__dirname, '/public');

// add logging middleware
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) {
github Azure / kubernetes-hackfest / app / data-updater / app.js View on Github external
db.on('error', err => {
  appInsights.defaultClient.trackEvent({ name: 'MongoConnError' });
  console.log(err);
});