在 Application Insights 中采样Sampling in Application Insights

采样是 Azure Application Insights 中的一项功能。Sampling is a feature in Azure Application Insights. 建议将它用于降低遥测流量、数据成本和存储成本,同时保留采用统计方式的应用程序数据的正确分析。It is the recommended way to reduce telemetry traffic, data costs, and storage costs, while preserving a statistically correct analysis of application data. 采样还有助于避免 Application Insights 限制遥测。Sampling also helps you avoid Application Insights throttling your telemetry. 采样筛选器会选择相关项,以便可以在执行诊断调查时在不同项之间导航。The sampling filter selects items that are related, so that you can navigate between items when you are doing diagnostic investigations.

当指标计数显示在门户中时,它们会重新规范化以考虑到采样。When metric counts are presented in the portal, they are renormalized to take into account sampling. 这样可以尽量减轻对统计的影响。Doing so minimizes any effect on the statistics.

简短摘要Brief summary

  • 有三种不同类型的采样:自适应采样、固定速率采样和引入采样。There are three different types of sampling: adaptive sampling, fixed-rate sampling, and ingestion sampling.
  • 默认情况下,已在所有最新版本的 Application Insights ASP.NET 和 ASP.NET Core 软件开发工具包 (SDK) 中启用自适应采样。Adaptive sampling is enabled by default in all the latest versions of the Application Insights ASP.NET and ASP.NET Core Software Development Kits (SDKs). Azure Functions 也使用自适应采样。It is also used by Azure Functions.
  • 固定速率采样可在最新版本的适用于 ASP.NET、ASP.NET Core、Java(代理和 SDK)和 Python 的 Application Insights SDK 中使用。Fixed-rate sampling is available in recent versions of the Application Insights SDKs for ASP.NET, ASP.NET Core, Java (both the agent and the SDK), and Python.
  • 引入采样适用于 Application Insights 服务终结点。Ingestion sampling works on the Application Insights service endpoint. 仅当没有其他采样生效时,才能应用引入采样。It only applies when no other sampling is in effect. 如果 SDK 为遥测数据采样,则会禁用引入采样。If the SDK samples your telemetry, ingestion sampling is disabled.
  • 对于 Web 应用程序,如果记录自定义事件,并需要确保事件集一同保留或一同丢弃,则事件必须具有相同的 OperationId 值。For web applications, if you log custom events and need to ensure that a set of events is retained or discarded together, the events must have the same OperationId value.
  • 如果要编写分析查询,应考虑采样If you write Analytics queries, you should take account of sampling. 特别是,应使用 summarize sum(itemCount),而不是仅对记录进行计数。In particular, instead of simply counting records, you should use summarize sum(itemCount).
  • 某些遥测类型(包括性能指标和自定义指标)始终会保留,而不管是否启用采样。Some telemetry types, including performance metrics and custom metrics, are always kept regardless of whether sampling is enabled or not.

下表汇总了适用于每个 SDK 和应用程序类型的采样类型:The following table summarizes the sampling types available for each SDK and type of application:

Application Insights SDKApplication Insights SDK 支持自适应采样Adaptive sampling supported 支持固定速率采样Fixed-rate sampling supported 支持引入采样Ingestion sampling supported
ASP.NETASP.NET 是(默认已启用)Yes (on by default) Yes 仅当没有其他采样生效时Only if no other sampling is in effect
ASP.NET CoreASP.NET Core 是(默认已启用)Yes (on by default) Yes 仅当没有其他采样生效时Only if no other sampling is in effect
Azure FunctionsAzure Functions 是(默认已启用)Yes (on by default) No 仅当没有其他采样生效时Only if no other sampling is in effect
JavaJava No Yes 仅当没有其他采样生效时Only if no other sampling is in effect
PythonPython No Yes 仅当没有其他采样生效时Only if no other sampling is in effect
所有其他All others No No Yes

备注

本页中的大部分信息适用于最新版本的 Application Insights SDK。The information on most of this page applies to the current versions of the Application Insights SDKs. 有关早期版本的 SDK 的信息,请参阅下面的部分For information on older versions of the SDKs, see the section below.

采样类型Types of sampling

有三种不同的采样方法:There are three different sampling methods:

  • 自适应采样自动调整从 ASP.NET/ASP.NET Core 应用中的 SDK 以及从 Azure Functions 发送的遥测量。Adaptive sampling automatically adjusts the volume of telemetry sent from the SDK in your ASP.NET/ASP.NET Core app, and from Azure Functions. 这是使用 ASP.NET 或 ASP.NET Core SDK 时的默认采样。This is the default sampling when you use the ASP.NET or ASP.NET Core SDK. 自适应采样目前仅适用于 ASP.NET 服务器端遥测,以及 Azure Functions。Adaptive sampling is currently only available for ASP.NET server-side telemetry, and for Azure Functions.

  • 固定速率采样会减少从 ASP.NET、ASP.NET Core 或 Java 服务器和用户浏览器发送的遥测量。Fixed-rate sampling reduces the volume of telemetry sent from both your ASP.NET or ASP.NET Core or Java server and from your users' browsers. 用户设定速率。You set the rate. 客户端和服务器将同步其采样,以便在“搜索”中可以在多个相关页面视图和请求之间导航。The client and server will synchronize their sampling so that, in Search, you can navigate between related page views and requests.

  • 引入采样在 Application Insights 服务终结点上发生。Ingestion sampling happens at the Application Insights service endpoint. 它会以设置的采样率丢弃一些来自应用的遥测数据。It discards some of the telemetry that arrives from your app, at a sampling rate that you set. 它不会减少应用发送的遥测流量,但可帮助保持在每月配额内。It doesn't reduce telemetry traffic sent from your app, but helps you keep within your monthly quota. 引入采样的大优点是,无需重新部署应用就可设置它。The main advantage of ingestion sampling is that you can set the sampling rate without redeploying your app. 引入采样统一适用于所有服务器和客户端,但在运行任何其他类型的采样时,不会应用引入采样。Ingestion sampling works uniformly for all servers and clients, but it does not apply when any other types of sampling are in operation.

重要

如果自适应或固定速率采样方法正在运行,将禁用引入采样。If adaptive or fixed rate sampling methods are in operation, ingestion sampling is disabled.

自适应采样Adaptive sampling

自适应采样会影响从 Web 服务器应用发送至 Application Insights 服务终结点的遥测量。Adaptive sampling affects the volume of telemetry sent from your web server app to the Application Insights service endpoint.

提示

使用 ASP.NET SDK 或 ASP.NET Core SDK 时,默认会启用自适应采样,并且默认会为 Azure Functions 启用它。Adaptive sampling is enabled by default when you use the ASP.NET SDK or the ASP.NET Core SDK, and is also enabled by default for Azure Functions.

遥测量会自动调整以保持在指定的最大流量率,可通过 MaxTelemetryItemsPerSecond 设置对其进行控制。The volume is adjusted automatically to keep within a specified maximum rate of traffic, and is controlled via the setting MaxTelemetryItemsPerSecond. 如果应用程序产生的遥测数据很少(例如在调试时或由于用量较小),则只要数量低于 MaxTelemetryItemsPerSecond,采样处理器就不会丢弃项目。If the application produces a low amount of telemetry, such as when debugging or due to low usage, items won't be dropped by the sampling processor as long as volume is below MaxTelemetryItemsPerSecond. 随着遥测数据量的增加,采样率将会调整以实现目标量。As the volume of telemetry increases, the sampling rate is adjusted so as to achieve the target volume. 调整会定期重新计算,计算依据是传出的传输速率的移动平均线。The adjustment is recalculated at regular intervals, and is based on a moving average of the outgoing transmission rate.

为了实现目标量,一些生成的遥测会被丢弃。To achieve the target volume, some of the generated telemetry is discarded. 但与其他类型的采样一样,该算法会保留相关的遥测项。But like other types of sampling, the algorithm retains related telemetry items. 例如,在“搜索”中检查遥测数据时,可以查找与特定异常相关的请求。For example, when you're inspecting the telemetry in Search, you'll be able to find the request related to a particular exception.

诸如请求速率和异常率等指标计数将进行调整以补偿采样率,以便它们在指标资源管理器中能够显示大约正确的值。Metric counts such as request rate and exception rate are adjusted to compensate for the sampling rate, so that they show approximately correct values in Metric Explorer.

为 ASP.NET 应用程序配置自适应采样Configuring adaptive sampling for ASP.NET applications

备注

本部分适用于 ASP.NET 应用程序,而不适用于 ASP.NET Core 应用程序。This section applies to ASP.NET applications, not to ASP.NET Core applications. 稍后在本文档中了解如何为 ASP.NET Core 应用程序配置自适应采样。Learn about configuring adaptive sampling for ASP.NET Core applications later in this document.

ApplicationInsights.config 中,可以在 AdaptiveSamplingTelemetryProcessor 节点中调整多个参数。In ApplicationInsights.config, you can adjust several parameters in the AdaptiveSamplingTelemetryProcessor node. 显示的数字是默认值:The figures shown are the default values:

  • <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>

    自适应算法的目标速率旨在针对每个服务器主机The target rate that the adaptive algorithm aims for on each server host. 如果在多台主机上运行 Web 应用,应减小此值以保留在 Application Insights 门户的目标流量速率以内。If your web app runs on many hosts, reduce this value so as to remain within your target rate of traffic at the Application Insights portal.

  • <EvaluationInterval>00:00:15</EvaluationInterval>

    会重新评估当前遥测速率的间隔。The interval at which the current rate of telemetry is reevaluated. 评估以移动平均线形式进行执行。Evaluation is performed as a moving average. 可能想要缩短此间隔(如果遥测很容易就激增)。You might want to shorten this interval if your telemetry is liable to sudden bursts.

  • <SamplingPercentageDecreaseTimeout>00:02:00</SamplingPercentageDecreaseTimeout>

    当采样百分比值更改时,多久后我们可以再次降低采样百分比以便捕获更少数据?When sampling percentage value changes, how soon after are we allowed to lower the sampling percentage again to capture less data?

  • <SamplingPercentageIncreaseTimeout>00:15:00</SamplingPercentageIncreaseTimeout>

    当采样百分比值更改时,多久后我们可以再次增加采样百分比以便捕获更多数据?When sampling percentage value changes, how soon after are we allowed to increase the sampling percentage again to capture more data?

  • <MinSamplingPercentage>0.1</MinSamplingPercentage>

    随着采样百分比的变化,我们可以设置的最小值是多少?As sampling percentage varies, what is the minimum value we're allowed to set?

  • <MaxSamplingPercentage>100.0</MaxSamplingPercentage>

    随着采样百分比的变化,我们可以设置的最大值是多少?As sampling percentage varies, what is the maximum value we're allowed to set?

  • <MovingAverageRatio>0.25</MovingAverageRatio>

    在移动平均的计算中,此参数指定要分配给最新值的权重。In the calculation of the moving average, this specifies the weight that should be assigned to the most recent value. 使用等于或小于 1 的值。Use a value equal to or less than 1. 较小的值会使算法不易受突然的更改影响。Smaller values make the algorithm less reactive to sudden changes.

  • <InitialSamplingPercentage>100</InitialSamplingPercentage>

    应用刚刚启动时要采样的遥测量。The amount of telemetry to sample when the app has just started. 在调试时请不要减小此值。Don't reduce this value while you're debugging.

  • <ExcludedTypes>Trace;Exception</ExcludedTypes>

    不要采样的类型的分号分隔列表。A semi-colon delimited list of types that you do not want to be subject to sampling. 识别的类型为:DependencyEventExceptionPageViewRequestTraceRecognized types are: Dependency, Event, Exception, PageView, Request, Trace. 将传输指定类型的所有遥测;将对未指定的类型采样。All telemetry of the specified types is transmitted; the types that are not specified will be sampled.

  • <IncludedTypes>Request;Dependency</IncludedTypes>

    要采样的类型的分号分隔列表。A semi-colon delimited list of types that you do want to subject to sampling. 识别的类型为:DependencyEventExceptionPageViewRequestTraceRecognized types are: Dependency, Event, Exception, PageView, Request, Trace. 将对指定的类型采样;始终会传输其他类型的所有遥测。The specified types will be sampled; all telemetry of the other types will always be transmitted.

若要关闭自适应采样,请从 ApplicationInsights.config 中删除 AdaptiveSamplingTelemetryProcessor 节点。To switch off adaptive sampling, remove the AdaptiveSamplingTelemetryProcessor node(s) from ApplicationInsights.config.

替换项:在代码中配置自适应采样Alternative: Configure adaptive sampling in code

除了在 .config 文件中设置采样参数以外,还可以编程方式设置这些值。Instead of setting the sampling parameter in the .config file, you can programmatically set these values.

  1. .config 文件中删除所有 AdaptiveSamplingTelemetryProcessor 节点。Remove all the AdaptiveSamplingTelemetryProcessor node(s) from the .config file.

  2. 使用以下代码片段来配置自适应采样:Use the following snippet to configure adaptive sampling:

    using Microsoft.ApplicationInsights;
    using Microsoft.ApplicationInsights.Extensibility;
    using Microsoft.ApplicationInsights.WindowsServer.Channel.Implementation;
    using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
    
    // ...
    
    var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
    // For older versions of the Application Insights SDK, use the following line instead:
    // var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
    
    // Enable AdaptiveSampling so as to keep overall telemetry volume to 5 items per second.
    builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5);
    
    // If you have other telemetry processors:
    builder.Use((next) => new AnotherProcessor(next));
    
    builder.Build();
    

    了解遥测处理器。)(Learn about telemetry processors.)

也可以单独调整每个遥测类型的采样率,甚至可以完全排除特定类型的采取:You can also adjust the sampling rate for each telemetry type individually, or can even exclude certain types from being sampled at all:

// The following configures adaptive sampling with 5 items per second, and also excludes Dependency telemetry from being subjected to sampling.
builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

为 ASP.NET Core 应用程序配置自适应采样Configuring adaptive sampling for ASP.NET Core applications

ASP.NET Core 应用程序没有 ApplicationInsights.config,因此所有配置都是通过代码完成的。There is no ApplicationInsights.config for ASP.NET Core applications, so all configuration is done via code. 默认情况下会为所有 ASP.NET Core 应用程序启用自适应采样。Adaptive sampling is enabled by default for all ASP.NET Core applications. 你可以禁用或自定义采样行为。You can disable or customize the sampling behavior.

禁用自适应采样Turning off adaptive sampling

添加 Application Insights 服务时,可以在 Startup.cs 文件中的方法 ConfigureServices 内使用 ApplicationInsightsServiceOptions 来禁用默认采样功能:The default sampling feature can be disabled while adding Application Insights service, in the method ConfigureServices, using ApplicationInsightsServiceOptions within the Startup.cs file:

public void ConfigureServices(IServiceCollection services)
{
    // ...

    var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
    aiOptions.EnableAdaptiveSampling = false;
    services.AddApplicationInsightsTelemetry(aiOptions);

    //...
}

以上代码将禁用自适应采样。The above code will disable adaptive sampling. 可以执行以下步骤使用更多自定义选项来添加采样。Follow the steps below to add sampling with more customization options.

配置采样设置Configure sampling settings

如下所示使用 TelemetryProcessorChainBuilder 的扩展方法来自定义采样行为。Use extension methods of TelemetryProcessorChainBuilder as shown below to customize sampling behavior.

重要

如果使用此方法配置采样,请确保在调用 AddApplicationInsightsTelemetry() 时将 aiOptions.EnableAdaptiveSampling 属性设置为 falseIf you use this method to configure sampling, please make sure to set the aiOptions.EnableAdaptiveSampling property to false when calling AddApplicationInsightsTelemetry().

public void Configure(IApplicationBuilder app, IHostingEnvironment env, TelemetryConfiguration configuration)
{
    var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
    // For older versions of the Application Insights SDK, use the following line instead:
    // var builder = configuration.TelemetryProcessorChainBuilder;

    // Using adaptive sampling
    builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5);

    // Alternately, the following configures adaptive sampling with 5 items per second, and also excludes DependencyTelemetry from being subject to sampling.
    // builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");

    // If you have other telemetry processors:
    builder.Use((next) => new AnotherProcessor(next));
    
    builder.Build();

    // ...
}

为 Azure Functions 配置自适应采样Configuring adaptive sampling for Azure Functions

固定速率采样Fixed-rate sampling

固定速率采样会减少从 Web 服务器和 Web 浏览器发送的流量。Fixed-rate sampling reduces the traffic sent from your web server and web browsers. 与自适应采样不同,它会按用户确定的固定速率来降低遥测。Unlike adaptive sampling, it reduces telemetry at a fixed rate decided by you. 固定速率采样适用于 ASP.NET、ASP.NET Core、Java 和 Python 应用程序。Fixed-rate sampling is available for ASP.NET, ASP.NET Core, Java and Python applications.

与其他采样方法一样,此方法也会保留相关的项。Like other sampling techniques, this also retains related items. 它还将同步客户端和服务器采样,以便保留相关项,例如,如果在“搜索”中查看页面视图,可以查找其相关的服务器请求。It also synchronizes the client and server sampling so that related items are retained - for example, when you look at a page view in Search, you can find its related server requests.

在指标资源管理器中,诸如请求和异常计数等速率将乘以某个系数来补偿采样率,以便它们大致正确。In Metrics Explorer, rates such as request and exception counts are multiplied by a factor to compensate for the sampling rate, so that they are approximately correct.

为 ASP.NET 应用程序配置固定速率采样Configuring fixed-rate sampling for ASP.NET applications

  1. 禁用自适应采样:在 ApplicationInsights.config 中,删除或注释掉 AdaptiveSamplingTelemetryProcessor 节点。Disable adaptive sampling: In ApplicationInsights.config, remove or comment out the AdaptiveSamplingTelemetryProcessor node.

    <TelemetryProcessors>
        <!-- Disabled adaptive sampling:
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
        </Add>
        -->
    
  2. 启用固定速率采样模块。Enable the fixed-rate sampling module. 将以下代码片段添加到 ApplicationInsights.configAdd this snippet to ApplicationInsights.config:

    <TelemetryProcessors>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.SamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <!-- Set a percentage close to 100/N where N is an integer. -->
            <!-- E.g. 50 (=100/2), 33.33 (=100/3), 25 (=100/4), 20, 1 (=100/100), 0.1 (=100/1000) -->
            <SamplingPercentage>10</SamplingPercentage>
        </Add>
    </TelemetryProcessors>
    

    如果不在 ApplicationInsights.config 文件中设置采样参数,可以编程方式设置这些值:Alternatively, instead of setting the sampling parameter in the ApplicationInsights.config file, you can programmatically set these values:

    using Microsoft.ApplicationInsights.Extensibility;
    using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
    
    // ...
    
    var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
    // For older versions of the Application Insights SDK, use the following line instead:
    // var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
    
    builder.UseSampling(10.0); // percentage
    
    // If you have other telemetry processors:
    builder.Use((next) => new AnotherProcessor(next));
    
    builder.Build();
    

    了解遥测处理器。)(Learn about telemetry processors.)

为 ASP.NET Core 应用程序配置固定速率采样Configuring fixed-rate sampling for ASP.NET Core applications

  1. 禁用自适应采样:可以在 ConfigureServices 方法中使用 ApplicationInsightsServiceOptions 进行更改:Disable adaptive sampling: Changes can be made in the ConfigureServices method, using ApplicationInsightsServiceOptions:

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
    
        var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
        aiOptions.EnableAdaptiveSampling = false;
        services.AddApplicationInsightsTelemetry(aiOptions);
    
        //...
    }
    
  2. 启用固定速率采样模块。Enable the fixed-rate sampling module. 可以在方法 Configure 中进行更改,如以下代码片段中所示:Changes can be made in the Configure method as shown in the below snippet:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        var configuration = app.ApplicationServices.GetService<TelemetryConfiguration>();
    
        var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
        // For older versions of the Application Insights SDK, use the following line instead:
        // var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
    
        // Using fixed rate sampling   
        double fixedSamplingPercentage = 10;
        builder.UseSampling(fixedSamplingPercentage);
    
        builder.Build();
    
        // ...
    }
    

为 Java 应用程序配置固定速率采样Configuring fixed-rate sampling for Java applications

默认情况下,Java 代理和 SDK 中不启用任何采样。By default no sampling is enabled in the Java agent and SDK. 目前,它仅支持固定速率采样。Currently it only supports fixed rate sampling. Java 不支持自适应采样。Adaptive sampling is not supported in Java.

配置 Java 代理Configuring Java Agent

  1. 下载 applicationinsights-agent-3.0.0-PREVIEW.5.jarDownload applicationinsights-agent-3.0.0-PREVIEW.5.jar

  2. 若要启用采样,请将以下内容添加到 ApplicationInsights.json 文件:To enable sampling add the following to your ApplicationInsights.json file:

{
  "instrumentationSettings": {
    "preview": {
      "sampling": {
        "fixedRate": {
          "percentage": 10 //this is just an example that shows you how to enable only only 10% of transaction 
        }
      }
    }
  }
}

配置 Java SDKConfiguring Java SDK

  1. 使用最新的 Application Insights Java SDK 下载并配置 Web 应用程序。Download and configure your web application with the latest Application Insights Java SDK.

  2. 通过将以下代码片段添加到 ApplicationInsights.xml 文件,来启用固定速率采样模块Enable the fixed-rate sampling module by adding the following snippet to ApplicationInsights.xml file:

    <TelemetryProcessors>
        <BuiltInProcessors>
            <Processor type="FixedRateSamplingTelemetryProcessor">
                <!-- Set a percentage close to 100/N where N is an integer. -->
                <!-- E.g. 50 (=100/2), 33.33 (=100/3), 25 (=100/4), 20, 1 (=100/100), 0.1 (=100/1000) -->
                <Add name="SamplingPercentage" value="50" />
            </Processor>
        </BuiltInProcessors>
    </TelemetryProcessors>
    
  3. 可以通过在 Processor 标记的 FixedRateSamplingTelemetryProcessor 中使用以下标记,在采样中包含或排除特定类型的遥测:You can include or exclude specific types of telemetry from sampling using the following tags inside the Processor tag's FixedRateSamplingTelemetryProcessor:

    <ExcludedTypes>
        <ExcludedType>Request</ExcludedType>
    </ExcludedTypes>
    
    <IncludedTypes>
        <IncludedType>Exception</IncludedType>
    </IncludedTypes>
    

可以在采样中包含或排除的遥测类型是:DependencyEventExceptionPageViewRequestTraceThe telemetry types that can be included or excluded from sampling are: Dependency, Event, Exception, PageView, Request, and Trace.

备注

对于采样百分比,请选择一个接近于 100/N 的百分比,其中 N 是整数。For the sampling percentage, choose a percentage that is close to 100/N where N is an integer. 当前采样不支持其他值。Currently sampling doesn't support other values.

为 OpenCensus Python 应用程序配置固定速率采样Configuring fixed-rate sampling for OpenCensus Python applications

使用最新的 OpenCensus Azure Monitor 导出程序检测应用程序。Instrument your application with the latest OpenCensus Azure Monitor exporters.

备注

固定速率采样不适用于指标导出程序。Fixed-rate sampling is not available for the metrics exporter. 这意味着,自定义指标是唯一不能配置采样的遥测类型。This means custom metrics are the only types of telemetry where sampling can NOT be configured. 指标导出程序将发送它跟踪的所有遥测数据。The metrics exporter will send all telemetry that it tracks.

用于跟踪的固定速率采样Fixed-rate sampling for tracing

可以在 Tracer 配置中指定 samplerYou may specify a sampler as part of your Tracer configuration. 如果未提供显式采样器,则默认使用 ProbabilitySamplerIf no explicit sampler is provided, the ProbabilitySampler will be used by default. ProbabilitySampler 将使用默认采样率 1/10000,这意味着,每 10000 个请求中就会有一个发送到 Application Insights。The ProbabilitySampler would use a rate of 1/10000 by default, meaning one out of every 10000 requests will be sent to Application Insights. 如需指定采样率,请参阅下文。If you want to specify a sampling rate, see below.

若要指定采样率,请确保 Tracer 指定的采样器使用的采样率为 0.0 到 1.0(含)。To specify the sampling rate, make sure your Tracer specifies a sampler with a sampling rate between 0.0 and 1.0 inclusive. 采样率 1.0 代表 100%,这意味着所有请求都会作为遥测数据发送到 Application Insights。A sampling rate of 1.0 represents 100%, meaning all of your requests will be sent as telemetry to Application Insights.

tracer = Tracer(
    exporter=AzureExporter(
        instrumentation_key='00000000-0000-0000-0000-000000000000',
    ),
    sampler=ProbabilitySampler(1.0),
)

日志的固定速率采样Fixed-rate sampling for logs

可以通过修改 logging_sampling_rate 可选参数,为 AzureLogHandler 配置固定速率采样。You can configure fixed-rate sampling for AzureLogHandler by modifying the logging_sampling_rate optional argument. 如果未提供参数,将使用采样率 1.0。If no argument is supplied, a sampling rate of 1.0 will be used. 采样率 1.0 代表 100%,这意味着所有请求都会作为遥测数据发送到 Application Insights。A sampling rate of 1.0 represents 100%, meaning all of your requests will be sent as telemetry to Application Insights.

handler = AzureLogHandler(
    instrumentation_key='00000000-0000-0000-0000-000000000000',
    logging_sampling_rate=0.5,
)

为包含 JavaScript 的网页配置固定速率采样Configuring fixed-rate sampling for web pages with JavaScript

可将基于 JavaScript 的网页配置为使用 Application Insights。JavaScript-based web pages can be configured to use Application Insights. 遥测数据是从用户浏览器中运行的客户端应用程序发送的,可在任何服务器中托管页面。Telemetry is sent from the client application running within the user's browser, and the pages can be hosted from any server.

为 Application Insights 配置基于 JavaScript 的网页时,请修改从 Application Insights 门户获取的 JavaScript 代码片段。When you configure your JavaScript-based web pages for Application Insights, modify the JavaScript snippet that you get from the Application Insights portal.

提示

在包含 JavaScript 的 ASP.NET 应用中,该代码片段通常放在 _Layout.cshtml 中。In ASP.NET apps with JavaScript included, the snippet typically goes in _Layout.cshtml.

在检测密钥前插入类似于 samplingPercentage: 10, 的行:Insert a line like samplingPercentage: 10, before the instrumentation key:

<script>
    var appInsights = // ... 
    ({ 
      // Value must be 100/N where N is an integer.
      // Valid examples: 50, 25, 20, 10, 5, 1, 0.1, ...
      samplingPercentage: 10, 

      instrumentationKey: ...
    }); 

    window.appInsights = appInsights; 
    appInsights.trackPageView(); 
</script>

对于采样百分比,请选择一个接近于 100/N 的百分比,其中 N 是整数。For the sampling percentage, choose a percentage that is close to 100/N where N is an integer. 当前采样不支持其他值。Currently sampling doesn't support other values.

协调服务器端和客户端采样Coordinating server-side and client-side sampling

客户端 JavaScript SDK 与服务器端 SDK 一同参与固定速率采样。The client-side JavaScript SDK participates in fixed-rate sampling in conjunction with the server-side SDK. 检测的页面仅从服务器端 SDK 决定“纳入采样”的相同用户发送客户端遥测数据。The instrumented pages will only send client-side telemetry from the same user for which the server-side SDK made its decision to include in the sampling. 此逻辑旨在维持跨客户端和服务器端应用程序的用户会话的完整性。This logic is designed to maintain the integrity of user sessions across client- and server-side applications. 因此,通过 Application Insights 中的任何特定遥测项,可以找到此用户或会话的所有其他遥测项;在搜索中,可以在相关页面视图与请求之间导航。As a result, from any particular telemetry item in Application Insights you can find all other telemetry items for this user or session and in Search, you can navigate between related page views and requests.

如果客户端和服务器端遥测不显示协调的样本:If your client and server-side telemetry don't show coordinated samples:

  • 确认是否已同时在服务器和客户端上启用采样。Verify that you enabled sampling both on the server and client.
  • 检查在客户端和服务器上设置的采样百分比相同。Check that you set the same sampling percentage in both the client and server.
  • 确保 SDK 版本是 2.0 或更高版本。Make sure that the SDK version is 2.0 or above.

引入采样Ingestion sampling

当来自 Web 服务器、浏览器和设备的遥测数据抵达 Application Insights 服务终结点时,将运行引入采样。Ingestion sampling operates at the point where the telemetry from your web server, browsers, and devices reaches the Application Insights service endpoint. 尽管它未减少从应用发送的遥测流量,但它确实减少了由 Application Insights 处理和保留(并收费)的遥测量。Although it doesn't reduce the telemetry traffic sent from your app, it does reduce the amount processed and retained (and charged for) by Application Insights.

如果应用经常超过其每月配额,且没有使用任一种基于 SDK 的采样类型的选项,请使用此种类型的采样。Use this type of sampling if your app often goes over its monthly quota and you don't have the option of using either of the SDK-based types of sampling.

在“使用情况和预估成本”页面中设置采样率:Set the sampling rate in the Usage and estimated costs page:

从应用程序的“概述”边栏选项卡中,依次单击“设置”、“配额”、“示例”,选择采样率,然后单击“更新”。

与其他类型的采样一样,该算法会保留相关的遥测项。Like other types of sampling, the algorithm retains related telemetry items. 例如,在“搜索”中检查遥测数据时,可以查找与特定异常相关的请求。For example, when you're inspecting the telemetry in Search, you'll be able to find the request related to a particular exception. 诸如请求速率和异常率等指标计数会正确保留。Metric counts such as request rate and exception rate are correctly retained.

被采样丢弃的数据点将无法在任何 Application Insights 功能(如连续导出)中使用。Data points that are discarded by sampling are not available in any Application Insights feature such as Continuous Export.

当自适应采样或固定速率采样正在运行时,不会运行引入采样。Ingestion sampling doesn't operate while adaptive or fixed-rate sampling is in operation. 使用 ASP.NET SDK 或 ASP.NET Core SDK 时,或者在 Azure 应用服务中或使用状态监视器启用 Application Insights 时,默认会启用自适应采样。Adaptive sampling is enabled by default when the ASP.NET SDK or the ASP.NET Core SDK is being used, or when Application Insights is enabled in Azure App Service or by using Status Monitor. 当 Application Insights 服务终结点收到遥测数据时,它会检查遥测数据,如果报告的采样率小于 100%(表示正在对遥测数据采样),将忽略设置的引入采样率。When telemetry is received by the Application Insights service endpoint, it examines the telemetry and if the sampling rate is reported to be less than 100% (which indicates that telemetry is being sampled) then the ingestion sampling rate that you set is ignored.

警告

门户磁贴上显示的值表示为引入采样设置的值。The value shown on the portal tile indicates the value that you set for ingestion sampling. 如果任何类型的 SDK 采样(自适应采样或固定速率采样)正在运行,则此值不表示实际采样率。It doesn't represent the actual sampling rate if any sort of SDK sampling (adaptive or fixed-rate sampling) is in operation.

何时使用采样When to use sampling

一般情况下,对于大多数小型和中型应用程序,不需要采样。In general, for most small and medium size applications you don't need sampling. 通过收集所有用户活动的数据,获取最有用的诊断信息和最准确的统计。The most useful diagnostic information and most accurate statistics are obtained by collecting data on all your user activities.

采样的主要优势在于:The main advantages of sampling are:

  • 当应用以短时间间隔发送速率很高的遥测时,Application Insights 服务会删除(“限制”)数据点。Application Insights service drops ("throttles") data points when your app sends a very high rate of telemetry in a short time interval. 采样可以减少应用程序遭到限制的可能性。Sampling reduces the likelihood that your application will see throttling occur.
  • 保持在定价层的数据点配额以内。To keep within the quota of data points for your pricing tier.
  • 减少遥测集合中的网络流量。To reduce network traffic from the collection of telemetry.

应该使用哪种类型的采样?Which type of sampling should I use?

在以下情况下使用引入采样:Use ingestion sampling if:

  • 经常用完每月遥测配额。You often use your monthly quota of telemetry.
  • 收到来自用户 Web 浏览器的大量遥测数据。You're getting too much telemetry from your users' web browsers.
  • 使用的 SDK 版本不支持采样,例如版本早于 2 的 ASP.NET 版本。You're using a version of the SDK that doesn't support sampling - for example ASP.NET versions earlier than 2.

在以下情况下使用固定速率采样:Use fixed-rate sampling if:

  • 希望同步客户端和服务器之间的采样,因此,调查搜索中的事件时,可以在客户端和服务器上的相关事件之间导航,例如页面视图和 HTTP 请求。You want synchronized sampling between client and server so that, when you're investigating events in Search, you can navigate between related events on the client and server, such as page views and HTTP requests.
  • 对应用的适当采样百分比有信心。You are confident of the appropriate sampling percentage for your app. 它应该足够高以获取准确指标,但应低于超出定价配额和限制的速率。It should be high enough to get accurate metrics, but below the rate that exceeds your pricing quota and the throttling limits.

使用自适应采样:Use adaptive sampling:

如果使用其他采样格式的条件不适用,我们建议使用自适应采样。If the conditions to use the other forms of sampling do not apply, we recommend adaptive sampling. ASP.NET/ASP.NET Core SDK 中默认已启用此设置。This setting is enabled by default in the ASP.NET/ASP.NET Core SDK. 只有在达到特定的最低速率时,它才减少流量,因此,可能根本不会对使用率较低的站点采样。It will not reduce traffic until a certain minimum rate is reached, therefore low-use sites will probably not be sampled at all.

了解采样是否正在运行Knowing whether sampling is in operation

若要查找实际采样率(无论是否已应用),请使用如下所示的分析查询To discover the actual sampling rate no matter where it has been applied, use an Analytics query such as this:

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > ago(1d)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType

如果你发现任何类型的 RetainedPercentage 小于 100,则表示正在对该类型的遥测数据采样。If you see that RetainedPercentage for any type is less than 100, then that type of telemetry is being sampled.

重要

Application Insights 不会在任何采样方法中对会话、指标(包括自定义指标)或性能计数器遥测类型采样。Application Insights does not sample session, metrics (including custom metrics), or performance counter telemetry types in any of the sampling techniques. 这些类型始终会排除在采样之外,因为精度下降可能会给这些遥测类型造成很大的不利。These types are always excluded from sampling as a reduction in precision can be highly undesirable for these telemetry types.

采样的工作原理How sampling works

采样算法决定要丢弃哪些遥测项,以及要保留哪些遥测项。The sampling algorithm decides which telemetry items to drop, and which ones to keep. 无论采样是由 SDK 执行还是在 Application Insights 服务中执行,都是如此。This is true whether sampling is done by the SDK or in the Application Insights service. 采样决策取决于多个规则,目标是保留所有相互关联的数据点不变,同时在 Application Insights 中保持可操作和可靠而且即使有精简数据集的诊断体验。The sampling decision is based on several rules that aim to preserve all interrelated data points intact, maintaining a diagnostic experience in Application Insights that is actionable and reliable even with a reduced data set. 例如,如果应用在样本中包含失败的请求,则会保留附加的遥测项(例如,为此请求记录的异常和跟踪)。For example, if your app has a failed request included in a sample, the additional telemetry items (such as exception and traces logged for this request) will be retained. 采样会将它们一起保留或删除。Sampling either keeps or drops them all together. 因此,在 Application Insights 中查看请求详细信息时,始终可以看到请求以及其关联的遥测项。As a result, when you look at the request details in Application Insights, you can always see the request along with its associated telemetry items.

采样决定取决于请求的操作 ID,这意味着属于特定操作的所有遥测项不是被保留就是被删除。The sampling decision is based on the operation ID of the request, which means that all telemetry items belonging to a particular operation is either preserved or dropped. 对于未设置操作 ID 的遥测项(例如,异步线程报告的且没有 HTTP 上下文的遥测项),采样仅捕获每个类型的遥测项百分比。For the telemetry items that do not have an operation ID set (such as telemetry items reported from asynchronous threads with no HTTP context) sampling simply captures a percentage of telemetry items of each type.

当遥测发回给用户时,Application Insights 服务会以收集时所使用的同一采样百分比来调整指标,以补偿缺失的数据点。When presenting telemetry back to you, the Application Insights service adjusts the metrics by the same sampling percentage that was used at the time of collection, to compensate for the missing data points. 因此,当用户在 Application Insights 中查看遥测数据,会看到统计的正确近似值非常接近于实际值。Hence, when looking at the telemetry in Application Insights, the users are seeing statistically correct approximations that are very close to the real numbers.

近似值的准确性很大程度上取决于配置的采样百分比。The accuracy of the approximation largely depends on the configured sampling percentage. 此外,对于处理通常来自大量用户的类似请求的较大量的应用程序,准确性也会提升。Also, the accuracy increases for applications that handle a large volume of generally similar requests from lots of users. 相反,对于不处理大量负载的应用程序,不需要采样,因为这些应用程序通常可以发送其所有遥测的同时保持在配额以内,而不会因限制而造成数据丢失。On the other hand, for applications that don't work with a significant load, sampling is not needed as these applications can usually send all their telemetry while staying within the quota, without causing data loss from throttling.

常见问题Frequently asked questions

ASP.NET 和 ASP.NET Core SDK 中的默认采样行为是什么?What is the default sampling behavior in the ASP.NET and ASP.NET Core SDKs?

  • 如果使用上述 SDK 的某个最新版本,则默认会启用自适应采样:每秒采样 5 个遥测项。If you are using one of the latest versions of the above SDK, Adaptive Sampling is enabled by default with five telemetry items per second. 默认会添加两个 AdaptiveSamplingTelemetryProcessor 节点,其中一个节点在采样中包含 Event 类型,而另一个节点则从采样中排除 Event 类型。There are two AdaptiveSamplingTelemetryProcessor nodes added by default, and one includes the Event type in sampling, while the other excludes the Event type from sampling. 这种配置意味着 SDK 会尝试将遥测项限制为 Event 类型的 5 个遥测项以及所有其他类型的 5 个遥测项,因此确保独立于其他遥测类型对 Events 进行采样。This configuration means that the SDK will try to limit telemetry items to five telemetry items of Event types, and five telemetry items of all other types combined, thereby ensuring that Events are sampled separately from other telemetry types. 事件通常用于业务遥测,在大多数情况下不应受到诊断遥测量的影响。Events are typically used for business telemetry, and most likely should not be affected by diagnostic telemetry volumes.

    下面显示了生成的默认 ApplicationInsights.config 文件。The following shows the default ApplicationInsights.config file generated. 在 ASP.NET Core 中,代码中会启用相同的默认行为。In ASP.NET Core, the same default behavior is enabled in code. 使用本页前面部分中的示例可以更改此默认行为。Use the examples in the earlier section of this page to change this default behavior.

    <TelemetryProcessors>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
            <ExcludedTypes>Event</ExcludedTypes>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
            <IncludedTypes>Event</IncludedTypes>
        </Add>
    </TelemetryProcessors>
    

是否可以对遥测数据进行多次采样?Can telemetry be sampled more than once?

  • 否。No. 如果项已采样,则 SamplingTelemetryProcessor 将不考虑项的采样。SamplingTelemetryProcessors ignore items from sampling considerations if the item is already sampled. 对于引入采样也是如此,对于已在 SDK 本身中采样的项,它不会应用采样。The same is true for ingestion sampling as well, which won't apply sampling to those items already sampled in the SDK itself.

为何不采样简单“收集每个遥测类型 %X”?Why isn't sampling a simple "collect X percent of each telemetry type"?

  • 虽然此采样方法提供极高精度的指标近似值,但它会破坏每个用户、会话和请求关联诊断数据的能力,而这对于诊断而言很关键。While this sampling approach would provide with a high level of precision in metric approximations, it would break the ability to correlate diagnostic data per user, session, and request, which is critical for diagnostics. 因此,对于“收集 %X 应用用户的所有遥测项”或“收集 %X 应用请求的所有遥测数据”等策略,采样的效果更佳。Therefore, sampling works better with policies like "collect all telemetry items for X percent of app users", or "collect all telemetry for X percent of app requests". 对于与请求不关联的遥测项(如后台异步处理),回退为“收集每个遥测类型 %X 的所有项”。For the telemetry items not associated with the requests (such as background asynchronous processing), the fallback is to "collect X percent of all items for each telemetry type."

采样百分比是否随时间变化?Can the sampling percentage change over time?

  • 是,自适应采样会根据当前观察到的遥测量,逐渐更改采样百分比。Yes, adaptive sampling gradually changes the sampling percentage, based on the currently observed volume of the telemetry.

如果我使用固定速率采样,如何知道哪一个才样百分比最适合我的应用?If I use fixed-rate sampling, how do I know which sampling percentage will work the best for my app?

  • 一种方法是从自适应采样开始,了解应用选定的速率(请参阅上述问题),然后使用该速率切换到固定速率采样。One way is to start with adaptive sampling, find out what rate it settles on (see the above question), and then switch to fixed-rate sampling using that rate.

    否则,就必须猜测。Otherwise, you have to guess. 分析 Application Insights 中当前遥测使用量、观察出现的任何限制,并估计所收集的遥测量。Analyze your current telemetry usage in Application Insights, observe any throttling that is occurring, and estimate the volume of the collected telemetry. 这三个输入以及所选的定价层暗示你可能想要减少收集的遥测的数量。These three inputs, together with your selected pricing tier, suggest how much you might want to reduce the volume of the collected telemetry. 但是,用户数量的增加或遥测量中的某些其他变化可能导致估计无效。However, an increase in the number of your users or some other shift in the volume of telemetry might invalidate your estimate.

如果我配置的采样百分比过低,会发生什么情况?What happens if I configure the sampling percentage to be too low?

  • 当 Application Insights 尝试补偿数据量减少的数据可视化效果时,过低的采样百分比会导致过度采样,并降低近似值的准确性。Excessively low sampling percentages cause over-aggressive sampling, and reduce the accuracy of the approximations when Application Insights attempts to compensate the visualization of the data for the data volume reduction. 此外,诊断体验可能会受到负面影响,因此可能会采样某些很少出现的请求或缓慢请求。Also your diagnostic experience might be negatively impacted, as some of the infrequently failing or slow requests may be sampled out.

如果我配置的采样百分比过高,会发生什么情况?What happens if I configure the sampling percentage to be too high?

  • 将配置过高的采样百分比(力度不够)会导致收集的遥测量减少不够。Configuring too high a sampling percentage (not aggressive enough) results in an insufficient reduction in the volume of the collected telemetry. 仍可能会遇到与限制相关的遥测数据丢失,而使用 Application Insights 的成本可能因过高费用而超出预算。You may still experience telemetry data loss related to throttling, and the cost of using Application Insights might be higher than you planned due to overage charges.

可以在哪些平台上使用采样?On what platforms can I use sampling?

  • 如果 SDK 未执行采样,则对于过于特定量的任何遥测,自动运行引入采样。Ingestion sampling can occur automatically for any telemetry above a certain volume, if the SDK is not performing sampling. 例如,如果使用旧版 ASP.NET SDK 或 Java SDK,则此配置可正常运行。This configuration would work, for example, if you are using an older version of the ASP.NET SDK or Java SDK.
  • 如果使用最新 ASP.NET 或 ASP.NET Core SDK(托管在 Azure 中或者自己的服务器上),则默认运行自适应采样,不过可按如上所述切换到固定速率采样。If you're using the current ASP.NET or ASP.NET Core SDKs (hosted either in Azure or on your own server), you get adaptive sampling by default, but you can switch to fixed-rate as described above. 使用固定速率采样,浏览器 SDK 会自动同步到示例相关的事件。With fixed-rate sampling, the browser SDK automatically synchronizes to sample related events.
  • 如果使用最新的 Java 代理,可以配置 ApplicationInsights.json(对于 Java SDK,配置 ApplicationInsights.xml)来启用固定速率采样。If you're using the current Java agent, you can configure ApplicationInsights.json (for Java SDK, configure ApplicationInsights.xml) to turn on fixed-rate sampling. 默认情况下,采样处于关闭状态。Sampling is turned off by default. 使用固定速率采样时,浏览器 SDK 和服务器会自动同步到样本相关的事件。With fixed-rate sampling, the browser SDK and the server automatically synchronize to sample related events.

我总是想要查看某些罕见的事件。如何让它们通过采样模块?There are certain rare events I always want to see. How can I get them past the sampling module?

  • 为此,最佳方法是编写一个自定义的 TelemetryInitializer,以便在想要保留的遥测项中将 SamplingPercentage 设置为 100,如下所示。The best way to achieve this is to write a custom TelemetryInitializer, which sets the SamplingPercentage to 100 on the telemetry item you want retained, as shown below. 由于保证初始化程序将在遥测处理器(包括采样)之前运行,因此可以确保所有采样技术都会出于任何采样考虑而忽略此项目。As initializers are guaranteed to be run before telemetry processors (including sampling), this ensures that all sampling techniques will ignore this item from any sampling considerations. 自定义遥测初始化表达式在 ASP.NET SDK、ASP.NET Core SDK、JavaScript SDK 和 Java SDK 中可用。Custom telemetry initializers are available in the ASP.NET SDK, the ASP.NET Core SDK, the JavaScript SDK, and the Java SDK. 例如,可以使用 ASP.NET SDK 配置遥测初始化表达式:For example, you can configure a telemetry initializer using the ASP.NET SDK:

    public class MyTelemetryInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            if(somecondition)
            {
                ((ISupportSampling)telemetry).SamplingPercentage = 100;
            }
        }
    }
    

旧 SDK 版本Older SDK versions

自适应采样适用于 Application Insights SDK for ASP.NET v2.0.0-beta3 及更高版本、Microsoft.ApplicationInsights.AspNetCore SDK v2.2.0-beta1 及更高版本,默认已启用。Adaptive sampling is available for the Application Insights SDK for ASP.NET v2.0.0-beta3 and later, Microsoft.ApplicationInsights.AspNetCore SDK v2.2.0-beta1 and later, and is enabled by default.

固定速率采样是 ASP.NET 版本 2.0.0 及更高版本,以及 Java SDK 版本 2.0.1 及更高版本中的一项 SDK 功能。Fixed-rate sampling is a feature of the SDK in ASP.NET versions from 2.0.0 and Java SDK version 2.0.1 and onwards.

对于 ASP.NET SDK 的 v2.5.0-beta2 之前版本以及 ASP.NET Core SDK 的 v2.2.0-beta3 之前版本,采样决策基于定义“用户”的应用程序(即最典型 Web 应用程序)用户 ID 的哈希代码。Prior to v2.5.0-beta2 of the ASP.NET SDK, and v2.2.0-beta3 of ASP.NET Core SDK, the sampling decision was based on the hash of the user ID for applications that define "user" (that is, most typical web applications). 对于未定义用户的应用程序类型(如 Web 服务),采样决定取决于请求的操作 ID。For the types of applications that didn't define users (such as web services) the sampling decision was based on the operation ID of the request. 最新版本的 ASP.NET 和 ASP.NET Core SDK 使用操作 ID 做出采样决策。Recent versions of the ASP.NET and ASP.NET Core SDKs use the operation ID for the sampling decision.

后续步骤Next steps