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

如何通过applicationinsights.json配置Java应用指定Base name的依赖采样

问题:针对特定Base name的依赖调用采样配置不生效

我在AKS中部署了集成Application Insights的Java应用,通过applicationinsights.json配置监控。现在需要对拥有特定Base name属性值的依赖调用进行采样,尝试了包含严格匹配与正则匹配的配置但未生效,求可行的配置方案。

用户尝试的配置示例:

{
    "role": {
        "name": "ROLE_NAME"
    },
    "heartbeat": {
        "intervalSeconds": 60
    },
    "preview": {
        "processors": [
            {
                "type": "attribute",
                "actions": [
                    {
                        "key": "http.url",
                        "pattern": "(?<redacted>\\?.*)",
                        "replace": "\\?***",
                        "action": "mask"
                    }
                ],
                "id": "/log/maskQueryString"
            }
        ],
        "sampling": {
            "overrides": [
                {
                    "telemetryType": "dependency",
                    "attributes": [
                        {
                            "key": "Base name",
                            "value": "<value of the property>",
                            "matchType": "strict"
                        }
                    ],
                    "percentage": 0
                }
            ]
        }
    }
}

可行配置方案

核心问题是你用了显示名称"Base name"作为属性键,但Application Insights Java SDK中,依赖调用的Base name对应的标准属性键是dependency.target,这是配置不生效的关键原因。以下是修正后的配置:

1. 严格匹配特定Base name值

{
    "role": {
        "name": "ROLE_NAME"
    },
    "heartbeat": {
        "intervalSeconds": 60
    },
    "preview": {
        "processors": [
            {
                "type": "attribute",
                "actions": [
                    {
                        "key": "http.url",
                        "pattern": "(?<redacted>\\?.*)",
                        "replace": "\\?***",
                        "action": "mask"
                    }
                ],
                "id": "/log/maskQueryString"
            }
        ],
        "sampling": {
            "overrides": [
                {
                    "telemetryType": "dependency",
                    "attributes": [
                        {
                            "key": "dependency.target",
                            "value": "你的目标Base name值",
                            "matchType": "strict"
                        }
                    ],
                    "percentage": 0
                }
            ]
        }
    }
}

2. 正则匹配Base name值

如果需要匹配符合某类模式的Base name,使用matchType: regex:

{
    "role": {
        "name": "ROLE_NAME"
    },
    "heartbeat": {
        "intervalSeconds": 60
    },
    "preview": {
        "processors": [
            {
                "type": "attribute",
                "actions": [
                    {
                        "key": "http.url",
                        "pattern": "(?<redacted>\\?.*)",
                        "replace": "\\?***",
                        "action": "mask"
                    }
                ],
                "id": "/log/maskQueryString"
            }
        ],
        "sampling": {
            "overrides": [
                {
                    "telemetryType": "dependency",
                    "attributes": [
                        {
                            "key": "dependency.target",
                            "value": "^prefix.*suffix$",
                            "matchType": "regex"
                        }
                    ],
                    "percentage": 0
                }
            ]
        }
    }
}

额外注意事项

  • 确保使用Application Insights Java 3.x SDK,预览版采样处理器是3.x版本引入的特性。
  • 配置修改后需重启AKS中的应用Pod,让配置生效。
  • 可在Application Insights日志中验证:运行dependencies | where target == '你的目标值',确认采样规则是否生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 23:25:59