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

如何在本地开发环境配置Dapr向Application Insights发送遥测数据?

本地Dapr配置Azure Application Insights遥测的正确步骤

方案一:使用Dapr Azure App Insights Exporter组件

你之前的配置存在两个关键问题:

  • Components部分格式错误,需单独作为Component资源(或用---分隔在同一文件中)
  • 无需手动指定endpoint,组件会根据仪表密钥自动匹配对应区域的端点

正确的配置文件示例:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
spec:
  tracing:
    enabled: true
    samplingRate: "1" # 开发环境建议全采样
    exporter:
      type: azure-appinsights
      config:
        instrumentationKey: "你的App Insights仪表密钥"
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: azure-appinsights
spec:
  type: exporters.azure.appinsights
  version: v1
  metadata:
  - name: instrumentationKey
    value: "你的App Insights仪表密钥"

配置步骤:

  1. 确保本地已完成Dapr初始化(执行过dapr init)
  2. 将上述内容保存为dapr-config.yaml
  3. 启动.NET Web API时指定该配置:
    dapr run --app-id dotnet-api --app-port 5000 --config dapr-config.yaml
    
  4. 仪表密钥可从Azure门户的Application Insights实例概述页获取

方案二:使用OpenTelemetry协议直接发送

你之前的OTEL端点格式不正确,App Insights的OTEL追踪端点需要包含 ingestion 路径,且必须携带身份验证头。

正确的配置示例:

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: appconfig
  namespace: default
spec:
  tracing:
    samplingRate: "1"
    otel:
      endpointAddress: "https://westeurope-5.in.applicationinsights.azure.com/v1/traces"
      headers:
        Authorization: "InstrumentationKey 你的App Insights仪表密钥"

注意事项:

  • 端点的区域前缀(如westeurope-5)必须和你的App Insights实例区域完全匹配
  • 启动服务时同样通过--config参数指定该配置文件

验证方法

  1. 调用你的.NET Web API接口,触发几次服务调用
  2. 等待3-5分钟后,登录Azure门户的Application Insights实例
  3. 进入「搜索」页面,筛选「追踪」类型,即可看到Dapr自动捕获的服务间调用追踪数据
  4. 如果没有数据,可查看Dapr sidecar日志排查错误:
    dapr logs --app-id dotnet-api
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 21:37:22