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

使用REST API向Application Insights上报自定义事件失败求助

问题排查与修正方案

核心错误:用错了API接口

你调用的https://api.applicationinsights.io/v1/apps/appid/metadata是Application Insights的查询API元数据接口,作用是获取应用的元数据信息,完全不是用来上报自定义事件的接口。上报数据得用专门的Ingestion API(旧称Track API)。

正确的上报配置

  • 替换接口地址:改用Ingestion API的端点,地址固定为:

    https://dc.services.visualstudio.com/v2/track
    

    注意:不需要在URL里填appid,应用标识要放在请求体的iKey字段中。

  • 修正请求体格式:上报自定义事件的请求体必须符合标准结构,包含name、time、iKey(你的Application Insights Instrumentation Key)、data等必填字段,正确示例如下:

    {
      "name": "Microsoft.ApplicationInsights.Event",
      "time": "2024-02-12T12:00:00Z",
      "iKey": "你的Instrumentation Key",
      "data": {
        "baseType": "EventData",
        "baseData": {
          "name": "customEvents",
          "properties": {
            "customProperty": "customValue"
          }
        }
      }
    }
    
  • 调整请求头:Ingestion API不需要x-api-key,但必须设置Content-Type: application/json。如果用API密钥认证,要在请求头添加Authorization: ApiKey 你的API密钥(注意ApiKey后面有空格)。

额外验证项

  • 确认你的API密钥勾选了Ingest权限(创建API密钥时要选 ingestion 权限,不能只选查询权限)。
  • 数据上报后通常有5-15分钟的延迟,不要立刻查数据,等一段时间后再去Application Insights的「事件」或「日志」里搜索customEvents。

内容的提问来源于stack exchange,提问作者kumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 00:45:09