Application Insights-TelemetryClient-DependencyTelemetry-UseSampling
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Application Insights-TelemetryClient-DependencyTelemetry-UseSampling相关的知识,希望对你有一定的参考价值。
我正在尝试通过我的AppInsightsHelper类启用采样,该类启动Depedancy操作以跟踪性能。
这是我初始化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);
问题在于,上面的代码似乎忽略了Sampling设置,并且跟踪了所有操作。我还在UseAdaptiveSampling内包括了:excludeedTypes:“ Dependency”,以查看是否发生了任何事情,并且按预期,不忽略Dependencies。
如果是天蓝色函数,则可以通过host.json设置采样,有关详细信息,请参见here和here。示例如下:
{
"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。
以上是关于Application Insights-TelemetryClient-DependencyTelemetry-UseSampling的主要内容,如果未能解决你的问题,请参考以下文章
为啥 Testcontainers 不使用 application.properties / application.yaml?
在 Spring 的 application.yml 上获取 VCAP_APPLICATION 的 application_name 值
用于 Spring Boot 的 application.yml 与 application.properties