gpt4 book ai didi

c# - 应用程序洞察 - TelemetryClient - DependencyTelemetry - UseSampling

转载 作者:行者123 更新时间:2023-12-03 05:39:58 26 4
gpt4 key购买 nike

我正在尝试使用我的 AppInsightsHelper 类启用采样,该类启动依赖操作来跟踪性能。

这就是我初始化 TelematryClient 的方式:

 public ApplicationInsightsHelper(string key)
{
var config = TelemetryConfiguration.CreateDefault();
config.InstrumentationKey = key;
config.DefaultTelemetrySink.TelemetryProcessorChainBuilder.UseAdaptiveSampling(maxTelemetryItemsPerSecond: 1);

_telemetryClient = new TelemetryClient(config);
}

然后启动和停止操作:

   IOperationHolder<DependencyTelemetry> operation = null;
operation = _telemetryClient.StartOperation<DependencyTelemetry>(friendlyName);
operation.Telemetry.Name = friendlyName;
operation.Telemetry.Type = type;
operation.Telemetry.Timestamp = DateTime.UtcNow;

operation.Telemetry.Duration = DateTime.UtcNow - operation.Telemetry.Timestamp;
_telemetryClient.StopOperation(operation);

问题是上面的代码似乎忽略了采样设置并且所有操作都被跟踪。我还在 UseAdaptiveSampling 中添加了: exceptedTypes: "Dependency"以查看是否发生任何情况,并且正如预期的那样,依赖项不会被忽略。

最佳答案

如果是azure函数,可以通过host.json设置采样,参见herehere了解详情。示例如下:

{
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond" : 1
}
}
}
}

如果您想使用 TelemetryClient 进行设置,您应该遵循此 article 。在 azure 函数的构造函数中,使用如下代码:

        /// Using dependency injection will guarantee that you use the same configuration for telemetry collected automatically and manually.
public HttpTrigger2(TelemetryConfiguration telemetryConfiguration)
{
this.telemetryClient = new TelemetryClient(telemetryConfiguration);
}

但截至目前,有一个 issue通过使用 telemetryConfiguration。

关于c# - 应用程序洞察 - TelemetryClient - DependencyTelemetry - UseSampling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59631566/

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