适用于 Azure Functions 的 Application Insights 支持功能Application Insights for Azure Functions supported features

Azure Functions 提供与 Application Insights 的内置集成功能(通过 ILogger Interface 可用)。Azure Functions offers built-in integration with Application Insights, which is available through the ILogger Interface. 以下是当前受支持的功能列表。Below is the list of currently supported features. 有关入门信息,请参阅 Azure Functions 指南。Review Azure Functions' guide for Getting started.

有关 Functions 运行时版本的详细信息,请参阅此处For more information about Functions runtime versions, see here.

有关 Application Insights 的兼容版本的详细信息,请参阅依赖项For more information about compatible versions of Application Insights, see Dependencies.

支持的功能Supported features

Azure FunctionsAzure Functions V1V1 V2 和 V3V2 & V3
自动集合Automatic collection of
• 请求• Requests Yes Yes
• 异常• Exceptions Yes Yes
• 性能计数器• Performance Counters Yes Yes
• 依赖项• Dependencies
   — HTTP   — HTTP Yes
   — ServiceBus   — ServiceBus Yes
   — EventHub   — EventHub Yes
   — SQL   — SQL Yes
受支持的功能Supported features
• QuickPulse/LiveMetrics• QuickPulse/LiveMetrics Yes Yes
   — 安全控制通道   — Secure Control Channel Yes
• 采样• Sampling Yes Yes
• 检测信号• Heartbeats Yes
相关性Correlation
• ServiceBus• ServiceBus Yes
• EventHub• EventHub Yes
可配置Configurable
• 完全可配置。•Fully configurable.
请参阅 Azure Functions 了解相应说明。See Azure Functions for instructions.
请参阅 ASP.NET Core 了解所有选项。See ASP.NET Core for all options.
Yes

性能计数器Performance Counters

性能计数器的自动收集仅适用于 Windows 计算器。Automatic collection of Performance Counters only work Windows machines.

实时指标和安全控制通道Live Metrics & Secure Control Channel

指定的自定义筛选器条件将发回到 Application Insights SDK 中的“实时指标”组件。The custom filters criteria you specify are sent back to the Live Metrics component in the Application Insights SDK. 筛选器可能包含 customerID 等敏感信息。The filters could potentially contain sensitive information such as customerIDs. 可以使用机密 API 密钥确保通道安全。You can make the channel secure with a secret API key. 有关说明,请参阅确保控制通道安全See Secure the control channel for instructions.

采样Sampling

Azure Functions 默认在其配置中启用采样功能。Azure Functions enables Sampling by default in their configuration. 有关详细信息,请参阅配置采样For more information, see Configure Sampling.

如果你的项目依赖 Application Insights SDK 进行手动遥测跟踪,则当采样配置与 Functions 的采样配置不同时,可能会遇到奇怪的行为。If your project takes a dependency on the Application Insights SDK to do manual telemetry tracking, you may experience strange behavior if your sampling configuration is different than the Functions' sampling configuration.

我们建议使用与 Functions 相同的配置。We recommend using the same configuration as Functions. 使用 Functions v2,可以在构造函数中使用依赖注入获得相同的配置:With Functions v2, you can get the same configuration using dependency injection in your constructor:

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

public class Function1 
{

    private readonly TelemetryClient telemetryClient;

    public Function1(TelemetryConfiguration configuration)
    {
        this.telemetryClient = new TelemetryClient(configuration);
    }

    [FunctionName("Function1")]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger logger)
    {
        this.telemetryClient.TrackTrace("C# HTTP trigger function processed a request.");
    }
}