Visual Studio CodeLens 中的 Application Insights 遥测Application Insights telemetry in Visual Studio CodeLens

使用有关运行时异常和请求响应时间的遥测,可以批注 Web 应用代码中的方法。Methods in the code of your web app can be annotated with telemetry about run-time exceptions and request response times. 如果在应用程序中安装 Azure Application Insights,遥测会在 Visual Studio CodeLens 中显示,即每个函数顶端的备注,通常在此处查看有用的信息,例如引用函数的位置数量或最后编辑函数的人员。If you install Azure Application Insights in your application, the telemetry appears in Visual Studio CodeLens - the notes at the top of each function where you're used to seeing useful information such as the number of places the function is referenced or the last person who edited it.

CodeLens

备注

Visual Studio 2015 Update 3 和更高版本,或 开发者分析工具扩展的最新版本提供 CodeLens 中的 Application Insights。Application Insights in CodeLens is available in Visual Studio 2015 Update 3 and later, or with the latest version of Developer Analytics Tools extension. Visual Studio 的 Enterprise 和 Professional 版本提供 CodeLens。CodeLens is available in the Enterprise and Professional editions of Visual Studio.

在哪里查找 Application Insights 数据Where to find Application Insights data

在 Web 应用程序的公共请求方法的 CodeLens 指示器中查找 Application Insights 遥测。Look for Application Insights telemetry in the CodeLens indicators of the public request methods of your web application. CodeLens 指示器在 C# 和 Visual Basic 代码中的方法和其他声明上方显示。CodeLens indicators are shown above method and other declarations in C# and Visual Basic code. 如果 Application Insights 数据可用于某个方法,将看到请求和异常指示器,例如“100 个请求,1% 个失败”或“10 个异常”。If Application Insights data is available for a method, you'll see indicators for requests and exceptions such as "100 requests, 1% failed" or "10 exceptions." 单击 CodeLens 指示器了解更多详细信息。Click a CodeLens indicator for more details.

提示

在其他 CodeLens 指示器出现后,Application Insights 请求和异常指示器可能需要再过几秒才能加载。Application Insights request and exception indicators may take a few extra seconds to load after other CodeLens indicators appear.

CodeLens 中的异常Exceptions in CodeLens

屏幕截图显示了 CodeLens 中显示的 47 个异常。

异常 CodeLens 指示器会在处理方法提供的请求时,显示过去 24 小时内应用程序中发生的十五大最频繁发生的异常的数量。The exception CodeLens indicator shows the number of exceptions that have occurred in the past 24 hours from the 15 most frequently occurring exceptions in your application during that period, while processing the request served by the method.

若要查看更多详细信息,请单击异常 CodeLens 指示器:To see more details, click the exceptions CodeLens indicator:

  • 相对之前 24 小时的最近 24 小时内的异常数量的百分比变化The percentage change in number of exceptions from the most recent 24 hours relative to the prior 24 hours
  • 选择“转到代码” 可浏览引发异常的函数的源代码Choose Go to code to navigate to the source code for the function throwing the exception
  • 选择“搜索” 可查询过去 24 小时内发生此异常的所有实例Choose Search to query all instances of this exception that have occurred in the past 24 hours
  • 选择“趋势” 可查看过去 24 小时内此异常发生次数的区域可视化效果Choose Trend to view a trend visualization for occurrences of this exception in the past 24 hours
  • 选择“查看此应用中的所有异常” 可查询过去 24 小时内发生的所有异常Choose View all exceptions in this app to query all exceptions that have occurred in the past 24 hours
  • 选择“探索异常趋势” 可查看过去 24 小时内发生的所有异常的趋势可视化效果。Choose Explore exception trends to view a trend visualization for all exceptions that have occurred in the past 24 hours.

提示

如果在 CodeLens 中看到“0 个异常”,但知道应该有异常,请检查并确保在 CodeLens 中选择了正确的 Application Insights 资源。If you see "0 exceptions" in CodeLens but you know there should be exceptions, check to make sure the right Application Insights resource is selected in CodeLens. 要选择其他资源,请在解决方案资源管理器中右键单击项目,并选择“Application Insights”>“选择遥测源” 。To select another resource, right-click on your project in the Solution Explorer and choose Application Insights > Choose Telemetry Source. CodeLens 仅显示过去 24 小时内应用程序中的十五大最频繁发生的异常,因此,如果异常的发生频率排名第 16 位或发生频率更低,将看到“0 个异常”。CodeLens is only shown for the 15 most frequently occurring exceptions in your application in the past 24 hours, so if an exception is the 16th most frequently or less, you'll see "0 exceptions." ASP.NET 视图中的异常可能不会在生成这些视图的控制器方法中显示。Exceptions from ASP.NET views may not appear on the controller methods that generated those views.

提示

如果在 CodeLens 中看到“?If you see "? 个异常”,则需要将 Azure 帐户与 Visual Studio 关联,否则 Azure 帐户凭据可能会过期。exceptions" in CodeLens, you need to associate your Azure account with Visual Studio or your Azure account credential may have expired. 在任何一种情况下,单击“?In either case, click "? 个异常”,然后选择“添加帐户...” 以输入凭据。exceptions" and choose Add an account... to enter your credentials.

CodeLens 中的请求Requests in CodeLens

屏幕截图显示了 684 个请求的详细信息,包括 7% 的失败。

请求 CodeLens 指示器显示过去 24 小时内某个方法提供的 HTTP 请求的数量,以及失败请求的百分比。The request CodeLens indicator shows the number of HTTP requests that been serviced by a method in the past 24 hours, plus the percentage of those requests that failed.

若要查看更多详细信息,请单击请求 CodeLens 指示器:To see more details, click the requests CodeLens indicator:

  • 相对之前 24 小时的过去 24 小时内的请求数量、失败的请求和平均响应时间的绝对值和百分比变化The absolute and percentage changes in number of requests, failed requests, and average response times over the past 24 hours compared to the prior 24 hours
  • 方法的可靠性,通过计算过去 24 小时内未失败请求的百分比获得The reliability of the method, calculated as the percentage of requests that did not fail in the past 24 hours
  • 选择“搜索” 请求或失败的请求,可查询过去 24 小时内发生的所有(失败)请求Choose Search for requests or failed requests to query all the (failed) requests that occurred in the past 24 hours
  • 选择“趋势” 可查看过去 24 小时内的请求、失败的请求或平均响应时间的趋势可视化效果。Choose Trend to view a trend visualization for requests, failed requests, or average response times in the past 24 hours.
  • 选择 CodeLens 详细信息视图左上角的 Application Insights 资源名称,更改 CodeLens 数据源对应的资源。Choose the name of the Application Insights resource in the upper left corner of the CodeLens details view to change which resource is the source for CodeLens data.

后续步骤Next steps