我在我的应用程序中使用 Azure 服务(AppService、AppInsight)
此外,我已经实现了我的项目 int .net Core6
我正在使用
Microsoft.ApplicationInsights.AspNetCore
库(版本2.22.0
)
我的appsetting.json中的Application Insight配置是这样的
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=a91c943b-5268-42e1-80c3-dc03c5e9bf0c;IngestionEndpoint=https://easteurope.in.applicationinsights.azure.com/;LiveEndpoint=https://easteurope.livediagnostics.monitor.azure.com/"
}
我已经注册了应用程序洞察服务,如下所示:
builder.Services.AddApplicationInsightsTelemetry();
我的代码是
private readonly TelemetryClient telemetryClient;
public SaveMetricsUseCase(TelemetryClient telemetryClient)
{
this.telemetryClient = telemetryClient;
}
...
private void SaveMetrics() {
telemetryClient.GetMetric("ProjectName.PromptTokens", "CategoryId", "Model", "UserId")
.TrackValue(input.Prompt, input.CategoryId, input.ModelName, input.UserId);
telemetryClient.GetMetric("ProjectName.CompletionTokens", "CategoryId", "Model", "UserId")
.TrackValue(input.Completion, input.CategoryId, input.ModelName, input.UserId);
}
每当我在 AppService 上部署更改时,自定义指标都会正确保存,但在一小时之后,指标将停止存储,并且我无法再在 App Insight 门户中看到任何指标(其他日志和异常保存在 AppInsight 中没有问题,只是指标不再存储)
您知道问题出在哪里吗?
已解决
该问题与
valuesPerDimensionLimit
中的 MetricConfiguration
属性有关,根据 Microsoft 文档,每个维度的唯一值都有限制。当我们使用具有不同尺寸值(超过限制)的TrackValue
时,轨迹将不再被保存。