如何在 Azure Application Insights 中查看挂起的请求?

问题描述 投票:0回答:1

我在我的 .Net core/Angular Web 应用程序中实现了 Azure Application Insights 包。

程序.cs

services.AddApplicationInsightsTelemetry();

我创建了一个前端服务来记录客户端事件。

@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);
  }
}

我需要方法来跟踪我的应用程序中的挂起请求。目前,当我对请求等待 10 分钟来测试它时,该请求直到 10 分钟后从服务器返回才出现在分析器上。我如何查看正在等待的请求?

c# angular .net-core azure-application-insights azure-application-insights-profiler
1个回答
0
投票

简而言之,你不能。

Application Insights 的设计方式是在内存中生成请求遥测,并在完成后发送到内部缓冲区。仅在那一刻,才会设置请求详细信息(例如持续时间和结果代码)。如果在请求实际完成之前发送遥测数据,则 Microsoft 必须构建某种系统来在请求发送到 Application Insights 后端后设置此属性。我认为这将是一个重大挑战,要使其可靠。

您可以在请求启动时创建跟踪或自定义事件,然后在给定时间点创建一个查询,显示尚未将请求遥测作为父级的所有跟踪或事件,并计算自发送以来经过的时间痕迹或事件。

© www.soinside.com 2019 - 2024. All rights reserved.