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

Azure Application Insights Java SDK多遥测类型采样覆盖配置咨询

Azure Application Insights Java SDK 采样覆盖配置方案

一、满足需求的配置示例

你可以通过分层配置采样规则实现需求,以下是适配的applicationinsights.yml配置:

sampling:
  # 全局默认采样率100%
  percentage: 100
  overrides:
    # 规则1:健康检查请求跨度采样率0%
    - telemetry-type: request
      attributes:
        # 替换为你实际的健康检查请求标识,比如http路由或URL
        http.route: "/health-check"
      percentage: 0
    # 规则2:Trace类型默认采样率10%,匹配特定标识的Trace全量保留
    - telemetry-type: trace
      percentage: 10
      overrides:
        - attributes:
            # 此属性需通过自定义处理器从消息体提取后添加
            trace.has-audit-tag: "true"
          percentage: 100
    # 规则3:Dependency类型默认采样率25%
    - telemetry-type: dependency
      percentage: 25

二、你的疑问解答

1. 能否匹配Trace消息体中包含.audit的条目?

标准采样覆盖规则仅支持基于遥测的**attributes(属性)**做匹配,无法直接读取Trace的消息体内容。要实现该需求,需先通过自定义遥测处理器,将消息体是否包含.audit的判断结果作为新属性添加到遥测数据中,再在采样覆盖规则里匹配这个新属性。

核心逻辑示例(Java代码片段):

public class AuditTraceTagProcessor implements TelemetryProcessor {
    @Override
    public boolean process(Telemetry telemetry) {
        if (telemetry instanceof TraceTelemetry traceTelemetry) {
            String msg = traceTelemetry.getMessage();
            if (msg != null && msg.contains(".audit")) {
                traceTelemetry.getProperties().put("trace.has-audit-tag", "true");
            }
        }
        return true;
    }
}

注册该处理器后,即可在采样覆盖中匹配新增的属性。

2. 百分比采样场景下,遥测处理器是否适用?

遥测处理器仅能对遥测数据做全量过滤或修改(要么保留要么丢弃),无法实现基于概率的百分比采样逻辑。因此你的百分比采样需求必须通过官方的采样覆盖配置实现;遥测处理器仅适合作为辅助工具,解决采样覆盖无法直接处理的自定义匹配场景(比如上述提取消息体标识的操作)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 21:05:09