gpt4 book ai didi

c# - 禁用 Azure Insights 采样不起作用

转载 作者:行者123 更新时间:2023-12-02 07:17:37 26 4
gpt4 key购买 nike

我正在 .NET Core 3.1 中开发 Azure Function。我注意到它不会将所有所需的数据保存到 Azure Insights 中。可以肯定的是,我尝试在本地主机上运行我的函数,不仅向 AI 添加日志记录,而且每次我尝试将数据记录到 AI 时,我还创建了一个包含我想要的数据的文本文件登录到.创建的文本文件的数量与我的预期完全相同,而 AI 日志中的条目却少得多。

为了禁用采样,我尝试了host.json文件的各种配置,该文件的当前内容是:

  "version": "2.0",
"functionTimeout": "-1",
"logging": {
"fileLoggingMode": "always",
"logLevel": {
"default": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false,
"maxTelemetryItemsPerSecond": 10000,
"excludedTypes": "Debug,Trace,Warning,Error,Information,Critical"
}
}
}
}

(由于将 isEnabled 设置为 false 没有帮助,我还尝试设置每秒足够数量的最大遥测项目,但它也没有帮助)

它不起作用(无论是在我的本地计算机上还是部署在 Azure 上);我还尝试通过代码禁用它:

namespace MyAzureFunction
{
public class MyStartup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var configDescriptor = builder.Services.SingleOrDefault(tc => tc.ServiceType == typeof(TelemetryConfiguration));
if (configDescriptor?.ImplementationFactory != null)
{
var aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.EnableAdaptiveSampling = false;

var implFactory = configDescriptor.ImplementationFactory;
builder.Services.Remove(configDescriptor);
builder.Services.AddSingleton(provider =>
{
if (implFactory.Invoke(provider) is TelemetryConfiguration config)
{
var newConfig = TelemetryConfiguration.Active;
newConfig.ApplicationIdProvider = config.ApplicationIdProvider;
newConfig.InstrumentationKey = config.InstrumentationKey;
return newConfig;
}
return null;
});

builder.Services.AddApplicationInsightsTelemetry(aiOptions);
}
}
}

此外,当我在本地主机上运行我的函数时,这就是我在命令行窗口中看到的内容:

[2022-08-24T13:37:55.249Z] {
[2022-08-24T13:37:55.250Z] "version": "2.0",
[2022-08-24T13:37:55.252Z] "functionTimeout": "-1",
[2022-08-24T13:37:55.253Z] "logging": {
[2022-08-24T13:37:55.254Z] "fileLoggingMode": "always",
[2022-08-24T13:37:55.255Z] "logLevel": {
[2022-08-24T13:37:55.257Z] "default": "Information"
[2022-08-24T13:37:55.258Z] },
[2022-08-24T13:37:55.259Z] "applicationInsights": {
[2022-08-24T13:37:55.260Z] "samplingSettings": {
[2022-08-24T13:37:55.262Z] "isEnabled": false,
(...)
[2022-08-24T13:37:57.043Z] Initializing Host. OperationId: ...
[2022-08-24T13:37:57.055Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=...
[2022-08-24T13:37:57.087Z] ApplicationInsightsLoggerOptions
[2022-08-24T13:37:57.089Z] {
[2022-08-24T13:37:57.089Z] "SamplingSettings": null,
[2022-08-24T13:37:57.090Z] "SamplingExcludedTypes": null,
[2022-08-24T13:37:57.091Z] "SamplingIncludedTypes": null,
[2022-08-24T13:37:57.092Z] "SnapshotConfiguration": null,

如您所见,即使它在关闭采样的情况下读取主机配置,SamplingSettings 仍为空,但我找不到有效禁用它的方法。

最佳答案

我已尝试重现您的问题。禁用采样后,我能够在应用程序洞察中获取所有遥测信息。

  • 感谢 @Andrew S,您的建议检查 Azure Application Insights 资源中的采样率为 100%
  • 根据请求的操作 ID 进行采样。与特定操作关联的遥测项目将被保留或删除。

解决方法如下

我使用了与您相同的 host.json 文件配置。

  "version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": false,
"maxTelemetryItemsPerSecond": 10000,
"excludedTypes": "Debug,Trace,Warning,Error,Information,Critical"
}
}
}
}

startup.cs 中禁用采样

  var aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.EnableAdaptiveSampling = false;
builder.Services.AddApplicationInsightsTelemetry(aiOptions);

我从本地和Azure得到的结果:本地的 enter image description here

在 Azure 中部署相同的功能host.json enter image description here

KUDU 中生成的日志文件 enter image description here

人工智能结果 enter image description here

关于c# - 禁用 Azure Insights 采样不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73474282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com