Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ns: any = cls.createNamespace('my.request');
// This is the currently recommended work-around for using Application Insights with async/await
// https://github.com/Microsoft/ApplicationInsights-node.js/issues/296
// This allows AppInsights to automatically apply the appropriate context objects deep inside the async/await chain.
// tslint:disable-next-line:no-submodule-imports
import { CorrelationContext, CorrelationContextManager } from 'applicationinsights/out/AutoCollection/CorrelationContextManager';
const origGetCurrentContext: any = CorrelationContextManager.getCurrentContext;
function getCurrentContext(): any {
// tslint:disable-next-line:no-backbone-get-set-outside-model
return ns.get('ctx') || origGetCurrentContext();
}
// Overwrite the built-in getCurrentContext() method with a new one.
CorrelationContextManager.getCurrentContext = getCurrentContext;
export const ApplicationInsightsWebserverMiddleware: any = (req: any, res: any, next: any): void => {
// Check to see if the request contains an incoming request.
// If so, set it into the Application Insights context.
const activity: Partial = req.body;
if (activity && activity.id) {
const context: CorrelationContext = appInsights.getCorrelationContext();
// tslint:disable-next-line:no-string-literal
context['activity'] = req.body;
}
ns.bindEmitter(req);
ns.bindEmitter(res);
ns.run((): void => {
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import * as appInsights from 'applicationinsights';
import { Activity, BotTelemetryClient, TelemetryDependency, TelemetryEvent, TelemetryException, TelemetryTrace } from 'botbuilder-core';
import * as cls from 'cls-hooked';
const ns: any = cls.createNamespace('my.request');
// This is the currently recommended work-around for using Application Insights with async/await
// https://github.com/Microsoft/ApplicationInsights-node.js/issues/296
// This allows AppInsights to automatically apply the appropriate context objects deep inside the async/await chain.
// tslint:disable-next-line:no-submodule-imports
import { CorrelationContext, CorrelationContextManager } from 'applicationinsights/out/AutoCollection/CorrelationContextManager';
const origGetCurrentContext: any = CorrelationContextManager.getCurrentContext;
function getCurrentContext(): any {
// tslint:disable-next-line:no-backbone-get-set-outside-model
return ns.get('ctx') || origGetCurrentContext();
}
// Overwrite the built-in getCurrentContext() method with a new one.
CorrelationContextManager.getCurrentContext = getCurrentContext;
export const ApplicationInsightsWebserverMiddleware: any = (req: any, res: any, next: any): void => {
// Check to see if the request contains an incoming request.
// If so, set it into the Application Insights context.
const activity: Partial = req.body;
if (activity && activity.id) {
const context: CorrelationContext = appInsights.getCorrelationContext();