How to use the applicationinsights.client 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 microsoft / ghcrawler / providers / logger / mockInsights.js View on Github external
static setup(key = null, echo = false) {
    // exit if we we are already setup
    if (appInsights.client instanceof MockInsights) {
      return;
    }
    if (!key || key === 'mock') {
      appInsights.client = new MockInsights();
    } else {
      appInsights
        .setup(key)
        .setAutoCollectPerformance(false)
        .setAutoCollectDependencies(false)
        .start();
      if (echo) {
        appInsights.client = new MockInsights(appInsights.client);
      }
    }
  }
github microsoft / ghcrawler / app.js View on Github external
const handler = function (error, request, response, next) {
  appInsights.client.trackException(error, { name: 'SvcRequestFailure' });
  if (response.headersSent) {
    return next(error);
  }
  response.status(error.status || 500);
  let propertiesToSerialize = ['success', 'message'];
  if (app.get('env') !== 'production') {
    propertiesToSerialize.push('stack');
  }
  // Properties on Error object aren't enumerable so need to explicitly list properties to serialize
  response.send(JSON.stringify(error, propertiesToSerialize));
  response.end();
};
app.use(handler);
github Azure / azure-xplat-cli / lib / util / telemetry.js View on Github external
exports.init = function (isEnabled) {
  _isEnabled = isEnabled;
  _subscription = _getCurrentSubscription();

  if (_isEnabled) {
    _appInsights.setup(Constants.TELEMETRY_INSTRUMENTATION_KEY)
      .setAutoCollectRequests(false)
      .setAutoCollectPerformance(false)
      .setAutoCollectExceptions(false);

    // Overwrite appinsight default values.
    var context = _appInsights.client.context;
    context.tags[context.keys.userId] = _subscription.user.id;

    _appInsights.start();
  }
};
github microsoft / ghcrawler / providers / logger / mockInsights.js View on Github external
static setup(key = null, echo = false) {
    // exit if we we are already setup
    if (appInsights.client instanceof MockInsights) {
      return;
    }
    if (!key || key === 'mock') {
      appInsights.client = new MockInsights();
    } else {
      appInsights
        .setup(key)
        .setAutoCollectPerformance(false)
        .setAutoCollectDependencies(false)
        .start();
      if (echo) {
        appInsights.client = new MockInsights(appInsights.client);
      }
    }
  }
github bragma / winston-azure-application-insights / lib / winston-azure-application-insights.js View on Github external
} else if (options.insights) {
		
		// If insights is set, just use the default client
		// We expect it to be already configured and started
		this.client = options.insights.client;
		
	} else {
		// Setup insights and start it
		// If options.key is defined, use it. Else the SDK will expect
		// an environment variable to be set.
		
		appInsights
			.setup(options.key)
			.start();
		
		this.client = appInsights.client; 
	}

	if (!this.client) {
		throw new Error('Could not get an Application Insights client instance');
	}
	
	this.name = WINSTON_LOGGER_NAME;
	this.level = options.level || WINSTON_DEFAULT_LEVEL;
	this.silent = options.silent || DEFAULT_IS_SILENT;
	this.treatErrorsAsExceptions = !!options.treatErrorsAsExceptions;
	
	// Setup AI here!
};
github mitchdenny / ecdc / lib / telemetry.ts View on Github external
export function trackEvent(code: string, properties?: { [key: string]: string; }, measurements?: { [key: string]: number; }) {
	let payload = {
		code: code,
		properties: properties,
		measurements: measurements
	};
	
	console.log(JSON.stringify(payload, null, '\t'));
	
	let configuration = vscode.workspace.getConfiguration('ecdc');
	let collectTelemetry = configuration.get('collectTelemetry');
	
	if (collectTelemetry) {
		ai.client.trackEvent(code, properties);	
	}
}
github Azure / azure-xplat-cli / lib / util / telemetry.js View on Github external
var _flush = function (callback) {
  if (_isEnabled) {
    _appInsights.client.sendPendingData(callback);
  }
};
github Azure / azure-xplat-cli / lib / util / telemetry.js View on Github external
exports.onError = function (err, callback) {
  if (_isEnabled && _event) {
    _stop(_event);
    _event.isSuccess = false;
    _event.stacktrace = _stripUsername(err.stack);
    _event.errorCategory = err.statusCode ? 'HTTP_Error_' + err.statusCode : 'CLI_Error';
    _appInsights.client.trackEvent('CmdletError', _event);
    _flush(callback);
  } else {
    callback();
  }
};
github Azure / azure-xplat-cli / lib / util / telemetry.js View on Github external
var _trackPageView = function (data) {
  var pageView = new _PageViewData();
  pageView.name = data.commandName;
  if (!isNaN(data.duration)) {
    pageView.duration = _msToTimeSpan(data.duration);
  }
  pageView.properties = data;
  var _data = new _Data();
  _data.baseType = 'PageViewData';
  _data.baseData = pageView;
  _appInsights.client.track(_data);
};