您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Application Insights 中的搜索Using Search in Application Insights

搜索是 Application Insights 中的一项功能,可用于查找和浏览单个遥测项,例如页面视图、异常或 Web 请求。Search is a feature of Application Insights that you use to find and explore individual telemetry items, such as page views, exceptions, or web requests. 此外,可以查看编写的日志跟踪和事件。And you can view log traces and events that you have coded.

(若要对数据进行更复杂的查询,请使用 Analytics。)(For more complex queries over your data, use Analytics.)

在 Azure 门户中In the Azure portal

可以从应用程序的“Application Insights 概览”边栏选项卡显式打开诊断搜索:You can open diagnostic search explicitly from the Application Insights Overview blade of your application:

打开诊断搜索

诊断搜索图的屏幕截图

诊断搜索的主体是遥测项列表 - 服务器请求、页面视图、编写的自定义事件,等等。The main body of Diagnostic Search is a list of telemetry items - server requests, page views, custom events that you have coded, and so on. 该列表的上面是摘要图表,显示一段时间内的事件计数。At the top of the list is a summary chart showing counts of events over time.

单击“刷新”获取新的事件。Click Refresh to get new events.

在 Visual Studio 中In Visual Studio

在 Visual Studio 中,也有一个 Application Insights 搜索窗口。In Visual Studio, there's also an Application Insights Search window. 该窗口最适合显示由正在进行调试的应用程序生成的遥测事件,It's most useful for displaying telemetry events generated by the application that you're debugging. 但也可显示从 Azure 门户的已发布应用收集的事件。But it can also show the events collected from your published app at the Azure portal.

在 Visual Studio 中打开“搜索”窗口:Open the Search window in Visual Studio:

Visual Studio 打开 Application Insights 搜索

“搜索”窗口的功能与 Web 门户类似:The Search window has features similar to the web portal:

Visual Studio Application Insights 搜索窗口

打开请求或页面视图即可使用“跟踪操作”选项卡。The Track Operation tab is available when you open a request or a page view. “操作”是一系列与单个请求或页面视图关联的事件。An 'operation' is a sequence of events that is associated with to a single request or page view. 例如,依赖项调用、异常、跟踪日志和自定义事件可能是单个操作的一部分。For example, dependency calls, exceptions, trace logs, and custom events might be part of a single operation. “跟踪操作”选项卡以图形方式显示这些事件相对于请求或页面视图的计时和持续时间。The Track Operation tab shows graphically the timing and duration of these events in relation to the request or page view.

检查单个项Inspect individual items

选择任一遥测项可查看关键字段和相关的项。Select any telemetry item to see key fields and related items.

单个依赖项请求的屏幕截图

这将启动端到端事务详细信息视图:This will launch the end-to-end transaction details view:

端到端事务详细信息视图的屏幕截图。

筛选事件类型Filter event types

打开“筛选”边栏选项卡,并选择要查看的事件类型。Open the Filter blade and choose the event types you want to see. (如果以后要还原打开边栏选项卡时所用的筛选器,请单击“重置”。)(If, later, you want to restore the filters with which you opened the blade, click Reset.)

选择筛选器并选择遥测类型

事件类型包括:The event types are:

  • 跟踪 - 诊断日志,包括 TrackTrace、log4Net、NLog 和 System.Diagnostic.Trace 调用。Trace - Diagnostic logs including TrackTrace, log4Net, NLog, and System.Diagnostic.Trace calls.
  • 请求 - 服务器应用程序收到的 HTTP 请求,包括页面、脚本、图像、样式文件和数据。Request - HTTP requests received by your server application, including pages, scripts, images, style files, and data. 这些事件用于创建请求和响应概述图表。These events are used to create the request and response overview charts.
  • 页面视图 - 由 Web 客户端发送的遥测数据,用于创建页面视图报告。Page View - Telemetry sent by the web client, used to create page view reports.
  • 自定义事件 - 如果插入了对 TrackEvent() 的调用以便监视使用情况,可以在此处搜索这些调用。Custom Event - If you inserted calls to TrackEvent() in order to monitor usage, you can search them here.
  • 异常 - 未捕获到的服务器中的异常,以及使用 TrackException() 记录的异常。Exception - Uncaught exceptions in the server, and those that you log by using TrackException().
  • 依赖项 - 发自服务器应用程序的调用,调用对象为 REST API 或数据库等其他服务器,以及客户端代码中的 AJAX 调用。Dependency - Calls from your server application to other services such as REST APIs or databases, and AJAX calls from your client code.
  • 可用性 - 可用性测试的结果。Availability - Results of availability tests.

按属性值筛选Filter on property values

可以按事件的属性值筛选事件。You can filter events on the values of their properties. 可用的属性取决于所选的事件类型。The available properties depend on the event types you selected.

例如,找出具有特定响应代码的请求。For example, pick out requests with a specific response code.

展开属性并选择值

不选择特定属性的任何值与选择所有值的效果相同;Choosing no values of a particular property has the same effect as choosing all values. 这会关闭根据该属性进行筛选的功能。It switches off filtering on that property.

请注意,筛选器值右侧的计数显示当前筛选的集内有多少个出现的项。Notice that the counts to the right of the filter values show how many occurrences there are in the current filtered set.

本示例清楚地显示“Rpt/Employees”请求导致“500”个错误中的大多数错误:In this example, it's clear that the 'Rpt/Employees' request results in most of the '500' errors:

展开属性并选择值

查找具有相同属性的事件Find events with the same property

查找具有相同属性值的所有项:Find all the items with the same property value:

右键单击属性

搜索数据Search the data

备注

若要编写更复杂的查询,请在“搜索”边栏选项卡的顶部打开 AnalyticsTo write more complex queries, open Analytics from the top of the Search blade.

可以搜索任何属性值中的关键词。You can search for terms in any of the property values. 如果已编写包含属性值的自定义事件,此功能特别有用。This is particularly useful if you have written custom events with property values.

可以设置时间范围,因为搜索一小段时间内的值可以更快地返回结果。You might want to set a time range, as searches over a shorter range are faster.

打开诊断搜索

搜索完整单词,而不搜索子字符串。Search for complete words, not substrings. 使用引号将特殊字符引起来。Use quotation marks to enclose special characters.

字符串string 不能使用以下项查找is not found by 但可使用以下项查找but these do find it
HomeController.AboutHomeController.About 主页home
controllercontroller
outout
homecontrollerhomecontroller
aboutabout
"homecontroller.about""homecontroller.about"
美国United States UniUni
tedted
unitedunited
statesstates
united AND statesunited AND states
"united states""united states"

下面是可以使用的搜索表达式:Here are the search expressions you can use:

示例查询Sample query 效果Effect
apple 在时间范围中查找字段包含“apple”一词的所有事件Find all events in the time range whose fields include the word "apple"
apple AND banana
apple banana
查找同时包含这两个词的事件。Find events that contain both words. 应使用大写“AND”,而不是“and”。Use capital "AND", not "and".
简格式。Short form.
apple OR banana 查找包含任一词的事件。Find events that contain either word. 使用“OR”而非“or”。Use "OR", not "or".
apple NOT banana 查找包含一个词但不包含另一个词的事件。Find events that contain one word but not the other.

采样Sampling

如果应用生成大量遥测(且使用的是 ASP.NET SDK 版本 2.0.0-beta3 或更高版本),自适应采样模块将通过仅发送具有代表性的事件部分来自动减少发送到门户的量。If your app generates a lot of telemetry (and you are using the ASP.NET SDK version 2.0.0-beta3 or later), the adaptive sampling module automatically reduces the volume that is sent to the portal by sending only a representative fraction of events. 但是,以组为单位选择或取消选择与同一请求相关的事件,以便可以在相关事件之间浏览。However, events that are related to the same request are selected or deselected as a group, so that you can navigate between related events.

了解采样Learn about sampling.

创建工作项Create work item

可以使用任何遥测项中的详细信息,在 GitHub 或 Azure DevOps 中创建 Bug。You can create a bug in GitHub or Azure DevOps with the details from any telemetry item.

单击“新建工作项”、编辑字段,并单击“确定”。

首次执行此操作时,系统将要求配置指向 Azure DevOps 组织和项目的链接。The first time you do this, you are asked to configure a link to your Azure DevOps organization and project.

请填写 Azure DevOps Services 的 URL 和项目名称,并单击“授权”

(还可以在“工作项”边栏选项卡上配置链接。)(You can also configure the link on the Work Items blade.)

将更多遥测数据发送到 Application InsightsSend more telemetry to Application Insights

除了 Application Insights SDK 原本发送的遥测数据以外,可以:In addition to the out-of-the-box telemetry sent by Application Insights SDK, you can:

  • .NETJava 中偏好的日志记录框架捕获日志跟踪。Capture log traces from your favorite logging framework in .NET or Java. 也就是说,可以搜索日志跟踪并将其与页面视图、异常和其他事件相关联。This means you can search through your log traces and correlate them with page views, exceptions, and other events.
  • 编写代码用于发送自定义事件、页面视图和异常。Write code to send custom events, page views, and exceptions.

了解如何向 Application Insights 发送日志和自定义的遥测数据Learn how to send logs and custom telemetry to Application Insights.

问题解答Q & A

保留多少数据?How much data is retained?

请参阅限制摘要See the Limits summary.

如何查看服务器请求中的 POST 数据?How can I see POST data in my server requests?

我们不自动记录 POST 数据,但可以使用 TrackTrace 或日志调用We don't log the POST data automatically, but you can use TrackTrace or log calls. POST 数据放在消息参数中。Put the POST data in the message parameter. 无法像筛选属性一样筛选消息,但消息的大小限制更大。You can't filter on the message in the same way you can filter on properties, but the size limit is longer.

视频Video

后续步骤Next steps