You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 02:17:56