Search code examples
c#angular.net-coreazure-application-insightsazure-application-insights-profiler

How do I view hanging requests in Azure Application Insights?


I implemented the Azure Application Insights package in my .Net core/angular web app.

Program.cs

services.AddApplicationInsightsTelemetry();

And I created a front end service to log client side events.

@Injectable()
export class AzureMonitoringService {
  private angularPlugin = new AngularPlugin();
  private appInsights: ApplicationInsights;
  
  constructor(private router: Router) {
    this.appInsights = new ApplicationInsights({
      config: {
        instrumentationKey: environment.instrumentationKey,
        enableAutoRouteTracking: true,
        enableAjaxErrorStatusText: true,
        extensions: [this.angularPlugin],
        extensionConfig: {
                [this.angularPlugin.identifier]: {
                    router: this.router,
                    errorServices: [new ErrorHandler()],
                },
            },
      }
    });
    this.appInsights.loadAppInsights();
  }

  logPageView(name?: string, url?: string) { // option to call manually
    this.appInsights.trackPageView({
      name: name,
      uri: url
    });
  }

  logEvent(name: string, properties?: { [key: string]: any }) {
    this.appInsights.trackEvent({ name: name}, properties);
  }

  logMetric(name: string, average: number, properties?: { [key: string]: any }) {
    this.appInsights.trackMetric({ name: name, average: average }, properties);
  }

  logException(exception: Error, severityLevel?: number) {
    this.appInsights.trackException({ exception: exception, severityLevel: severityLevel });
  }

  logTrace(message: string, properties?: { [key: string]: any }) {
    this.appInsights.trackTrace({ message: message}, properties);
  }
}

I need way to track hanging requests in my app. Currently, when I put a 10 minute wait on a request to test it, the request does not appear on the profiler until it returns from the server 10 minutes later. How can I see requests that are waiting?


Solution

  • In short, you can't.

    The way Application Insights is designed is that the request telemetry is generated in memory and send to an internal buffer once it is completed. Only at that moment the request details like duration and result code are set. If the telemetry would be send before the request is actually finished Microsoft must build some kind of system to set this properties after the request has been sent to the Application Insights backend. This would be a major challenge I can image to make that reliable.

    You could create a trace or custom event when the request is started and then at a given point in time create a query that shows all traces or events that do not yet have a request telemetry as parent and calculate the time that has passed since sending the trace or event.