How to use the applicationinsights.getCorrelationContext 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 / botbuilder-js / libraries / botbuilder-applicationinsights / src / applicationInsightsTelemetryClient.ts View on Github external
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();
  });

};
github microsoft / botbuilder-js / libraries / botbuilder-applicationinsights / src / telemetryInitializerMiddleware.ts View on Github external
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();
        }
    }
}