.NET Core6部署后App Insights自定义指标1小时后停止存储
问题描述
我的应用基于.NET Core 6开发,部署在Azure App Service上,使用Azure Application Insights服务,引用的Microsoft.ApplicationInsights.AspNetCore库版本为2.22.0。
配置与代码实现
AppInsights配置(appsettings.json)
"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); }
异常现象
每次将变更部署到App Service后,自定义指标能正常存储,但1小时后指标就停止写入,无法在App Insights门户中查询到新的指标数据;其他日志、异常等数据仍能正常保存到App Insights,仅自定义指标出现该问题。请问可能是什么原因导致的?
内容的提问来源于stack exchange,提问作者Mahdi Radi
相关产品推荐
相关产品推荐

