Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 => {
// tslint:disable-next-line:no-backbone-get-set-outside-model
ns.set('ctx', origGetCurrentContext());
next();
});
};
public async onTurn(context: TurnContext, next: () => Promise): Promise {
if (context === null) {
throw new Error('context is null');
}
if (context.activity && context.activity.id) {
const correlationContext: CorrelationContext = this._correlationContext || appInsights.getCorrelationContext();
if(correlationContext)
{
correlationContext['activity'] = context.activity;
}
}
if(this._logActivityTelemetry && this._telemetryLoggerMiddleware)
{
await this._telemetryLoggerMiddleware.onTurn(context, next);
}
else if (next !== null) {
await next();
}
}
}