How to use the applicationinsights.TelemetryClient 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 / 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 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 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;
    }
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;
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-assistant / src / adapters / defaultAdapter.ts View on Github external
this.userState = new UserState(storage);
        this.proactiveState = new ProactiveState(storage);

        if (settings.blobStorage === undefined) {
            throw new Error('There is no blobStorage value in appsettings file');
        }

        this.transcriptStore = new AzureBlobTranscriptStore({
            containerName: settings.blobStorage.container,
            storageAccountOrConnectionString: settings.blobStorage.connectionString
        });

        if (settings.appInsights === undefined) {
            throw new Error('There is no appInsights value in appsettings file');
        }
        this.telemetryClient = new TelemetryClient(settings.appInsights.instrumentationKey);

        // Use the AutoSaveStateMiddleware middleware to automatically read and write conversation and user state.
        this.use(new AutoSaveStateMiddleware(this.conversationState, this.userState));
        // Currently not working https://github.com/Microsoft/botbuilder-js/issues/853#issuecomment-481416004
        // this.use(new TranscriptLoggerMiddleware(this.transcriptStore));

        // Typing Middleware (automatically shows typing when the bot is responding/working)
        this.use(new ShowTypingMiddleware());
        if (settings.defaultLocale === undefined) {
            throw new Error('There is no defaultLocale value in appsettings file');
        }
        this.use(new SetLocaleMiddleware(settings.defaultLocale));
        this.use(new EventDebuggerMiddleware());
        this.use(new ProactiveStateMiddleware(this.proactiveState));
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 20.qna-with-appinsights / middleware / myAppInsightsMiddleware.js View on Github external
this.logOriginalMessage = false;
        this.appInsightsServiceKey = 'AppInsightsLoggerMiddleware.AppInsightsContext';

        if (!settings) {
            throw new Error('The settings parameter is required.');
        }
        if (!settings.instrumentationKey) {
            throw new Error('The settings.instrumentationKey parameter is required.');
        }
        if (settings.logUserName) {
            this.logUserName = settings.logUserName;
        }
        if (settings.logOriginalMessage) {
            this.logOriginalMessage = settings.logOriginalMessage;
        }
        this._telemetryClient = new TelemetryClient(settings.instrumentationKey);
    }