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

如何通过OpenTelemetry排除K8s Pod中指定Dotnet进程的追踪数据?

过滤K8s Pod中特定Dotnet进程的OpenTelemetry追踪数据

问题背景

Kubernetes Pod容器内运行两个Dotnet进程:主应用进程与ApplicareDotnetTrace.dll监控进程,Docker Entrypoint配置如下:

ENTRYPOINT sh -c "dotnet WebApplication1.dll & exec dotnet ./arc_dotnet/ApplicareDotnetTrace.dll"

使用OpenTelemetry Collector和Jaeger查看应用追踪时,ApplicareDotnetTrace.dll的无关追踪数据也会展示,需要过滤该进程的所有追踪信息。

已尝试在Pod YAML中添加以下环境变量,但未生效:

- name: OTEL_DOTNET_AUTO_EXCLUDE_PROCESS_ARGS
  value: "*ApplicareDotnetTrace.dll"
- name: OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES
  value: "ApplicareDotnetTrace.dll"  

当前Collector配置中已添加过滤处理器,但未达到预期效果:

filter/exclude_arc_process:
  traces:
    span:
      - 'resource.attributes["process.command_line"] == "dotnet ./arc_dotnet/ApplicareDotnetTrace.dll"'
      - 'name == "ApplicareDotnetTrace"'

解决方案

1. 修正Collector过滤规则

当前规则仅过滤单个span,需改为直接丢弃整个追踪链,同时适配shell包裹进程的命令行格式:

filter/exclude_arc_process:
  traces:
    trace:
      - 'resource.attributes["process.command_line"] matches ".*ApplicareDotnetTrace.dll.*"'
  • 使用trace级别过滤:直接丢弃该进程产生的所有追踪数据,而非单个span
  • 正则匹配命令行:由于进程通过sh -c启动,实际命令行包含完整shell指令,用matches和模糊正则避免精确匹配失败

2. 确保环境变量生效

OTEL_DOTNET_AUTO_EXCLUDE_*变量仅对OpenTelemetry .NET自动 instrumentation生效,需满足:

  • 应用已安装OpenTelemetry .NET自动 instrumentation依赖
  • 环境变量传递给所有子进程:当前Entrypoint用exec替换shell,可能导致第一个进程未继承环境变量,可修改Entrypoint:
ENTRYPOINT sh -c "dotnet WebApplication1.dll & dotnet ./arc_dotnet/ApplicareDotnetTrace.dll; wait"

3. 验证资源属性

通过Collector的debug exporter查看实际的process.command_line值,确认过滤规则的匹配项是否准确。例如查看debug日志中的resource.attributes字段,调整正则表达式以匹配真实的命令行格式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 12:12:33