ARMS支持通过Python探针对Dify应用进行可观测,Python探针是阿里云可观测产品自研的Python语言的可观测采集探针,其基于OpenTelemetry标准实现了自动化埋点能力。
前提条件
参考基于Dify构建网页定制化AI问答助手文档快速搭建一个Dify应用。
为Dify应用所在的ACK集群安装探针接入助手(ack-onepilot)、授予 ARMS 资源的访问权限,并开启应用监控。具体操作,请参见容器服务 ACK 和容器计算服务 ACS 通过 ack-onepilot 组件安装 Python 探针。
步骤一:监控 dify-api
获取启动脚本entrypoint.sh,并进行以下修改:
说明dify-api不建议开启ack-onepilot自动注入,否则可能存在venv环境异常和OTel插件兼容问题。
启动脚本开头添加如下命令,卸载冲突的插件,下载并安装 Python 探针。
python3 -m ensurepip --upgrade # 卸载冲突的OTel插件 pip3 uninstall -y opentelemetry-instrumentation-celery \ opentelemetry-instrumentation-flask \ opentelemetry-instrumentation-redis \ opentelemetry-instrumentation-requests \ opentelemetry-instrumentation-logging \ opentelemetry-instrumentation-wsgi \ opentelemetry-instrumentation-fastapi \ opentelemetry-instrumentation-asgi \ opentelemetry-instrumentation-sqlalchemy # 安装Python探针 pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip3 config set install.trusted-host mirrors.aliyun.com pip3 install aliyun-bootstrap && aliyun-bootstrap -a install脚本最后启动部分添加
aliyun-instrument启动命令。# 使用aliyun-instrument启动 exec aliyun-instrument gunicorn \ --bind "${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-5001}" \ --workers ${SERVER_WORKER_AMOUNT:-1} \ --worker-class ${SERVER_WORKER_CLASS:-gevent} \ --worker-connections ${SERVER_WORKER_CONNECTIONS:-10} \ --timeout ${GUNICORN_TIMEOUT:-200} \ app:app
配置环境变量。
变量名
示例值
说明
GEVENT_ENABLE
true
Dify 使用 gevent,必须设为true。
ARMS_APP_NAME
dify-api
应用名。
ARMS_REGION_ID
cn-heyuan
地域,修改为对应地域值。
ARMS_LICENSE_KEY
xxx
License Key。
APSARA_APM_APP_TYPE
microservice
将应用标识为微服务应用。
部署并查看监控数据:
可通过 Docker 数据卷挂载方式将原脚本替换为修改后的脚本(或直接修改源码中的启动脚本并重打镜像)。例如:将修改后的脚本 entrypoint.sh 存储为配置项,并挂载到容器目录
/app/api/docker,指定启动命令:["/bin/bash","/app/api/docker/entrypoint.sh"]进入应用监控列表可以看到 dify-api 应用并查看详情。

步骤二:监控dify-plugin-daemon
Dify-Plugin-Daemon 是 Dify 的插件管理器,Dify 的 LLM、插件、Agent 策略的执行都依赖 Plugin-Daemon。Go Agent支持监控 Dify-Plugin-Daemon,接入Go监控需修改Dockerfile、重新编译镜像后配置环境变量开启。Dify-Plugin-Daemon 的 Go 探针可以按需为插件运行时挂载 Python 探针,可以通过以下方式接入:
修改Dockerfile文件重新编译对应镜像。
以local.dockerfile为例,修改如下:
不监控Python Plugin
无需监控Python plugin时,Dockerfile修改如下:
FROM golang:1.23-alpine AS builder ARG VERSION=unknown # copy project COPY . /app # set working directory WORKDIR /app # using goproxy if you have network issues # ENV GOPROXY=https://goproxy.cn,direct # download arms instgo RUN wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo RUN chmod 777 instgo # instgo build RUN ./instgo go build \ -ldflags "\ -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.VersionX=${VERSION}' \ -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \ -o /app/main cmd/server/main.go # copy entrypoint.sh COPY entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh FROM ubuntu:24.04 WORKDIR /app # check build args ARG PLATFORM=local # Install python3.12 if PLATFORM is local RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl python3.12 python3.12-venv python3.12-dev python3-pip ffmpeg build-essential \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1; # preload tiktoken ENV TIKTOKEN_CACHE_DIR=/app/.tiktoken # Install dify_plugin to speedup the environment setup, test uv and preload tiktoken RUN mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.bk \ && python3 -m pip install uv \ && uv pip install --system dify_plugin \ && python3 -c "from uv._find_uv import find_uv_bin;print(find_uv_bin());" \ && python3 -c "import tiktoken; encodings = ['o200k_base', 'cl100k_base', 'p50k_base', 'r50k_base', 'p50k_edit', 'gpt2']; [tiktoken.get_encoding(encoding).special_tokens_set for encoding in encodings]" ENV UV_PATH=/usr/local/bin/uv ENV PLATFORM=$PLATFORM ENV GIN_MODE=release COPY --from=builder /app/main /app/entrypoint.sh /app/ # run the server, using sh as the entrypoint to avoid process being the root process # and using bash to recycle resources CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]监控Python Plugin
如果需要监控Python plugin,Dockerfile修改如下:
FROM golang:1.23-alpine AS builder ARG VERSION=unknown # copy project COPY . /app # set working directory WORKDIR /app # using goproxy if you have network issues # ENV GOPROXY=https://goproxy.cn,direct # download arms instgo RUN wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo RUN chmod 777 instgo # instgo build RUN INSTGO_EXTRA_RULES="dify_python" ./instgo go build \ -ldflags "\ -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.VersionX=${VERSION}' \ -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \ -o /app/main cmd/server/main.go # copy entrypoint.sh COPY entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh FROM ubuntu:24.04 WORKDIR /app # check build args ARG PLATFORM=local # Install python3.12 if PLATFORM is local RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl python3.12 python3.12-venv python3.12-dev python3-pip ffmpeg build-essential \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1; # preload tiktoken ENV TIKTOKEN_CACHE_DIR=/app/.tiktoken # Install dify_plugin to speedup the environment setup, test uv and preload tiktoken RUN mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.bk \ && python3 -m pip install uv \ && uv pip install --system dify_plugin \ && python3 -c "from uv._find_uv import find_uv_bin;print(find_uv_bin());" \ && python3 -c "import tiktoken; encodings = ['o200k_base', 'cl100k_base', 'p50k_base', 'r50k_base', 'p50k_edit', 'gpt2']; [tiktoken.get_encoding(encoding).special_tokens_set for encoding in encodings]" ENV UV_PATH=/usr/local/bin/uv ENV PLATFORM=$PLATFORM ENV GIN_MODE=release COPY --from=builder /app/main /app/entrypoint.sh /app/ # run the server, using sh as the entrypoint to avoid process being the root process # and using bash to recycle resources CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]部署dify-plugin-daemon应用并上报监控数据。
容器化部署
在dify-plugin-daemon应用的YAML文件中将以下
labels添加到spec.template.metadata层级下。labels: aliyun.com/app-language: golang armsPilotAutoEnable: 'on' armsPilotCreateAppName: "dify-daemon-plugin"非容器化部署
部署组件时请添加以下环境变量。
ARMS_LICENSE_KEY: xxx // 账号对应的ARMS LicenseKey ARMS_REGION_ID: cn-heyuan // 选择填写对应的RegionID ARMS_ENABLE: true ARMS_APP_NAME: dify-plugin-daemon您可以通过DescribeTraceLicenseKey OpenAPI获取LicenseKey。

查看dify-plugin-daemon监控。
在应用列表页面进入dify-plugin-daemon应用,监控详情如下:

调用链详情:

(可选)步骤三:监控dify-sandbox
Dify 1.0.0及以上版本引入了dify-sandbox用于管理插件的生命周期和后台任务调用等,如果需要监控该组件,可通过以下方式接入:
修改./build/build_[amd64|arm64].sh文件。
在文件中添加instgo下载命令。
下载命令示例如下,其他地域和架构的下载命令请参见下载 instgo。
wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo chmod 777 instgo在
go build前添加了instgo命令。
以amd64为例,修改示例如下:
rm -f internal/core/runner/python/python.so rm -f internal/core/runner/nodejs/nodejs.so rm -f /tmp/sandbox-python/python.so rm -f /tmp/sandbox-nodejs/nodejs.so wget "http://arms-apm-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/instgo/instgo-linux-amd64" -O instgo chmod 777 instgo echo "Building Python lib" CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ./instgo go build -o internal/core/runner/python/python.so -buildmode=c-shared -ldflags="-s -w" cmd/lib/python/main.go && echo "Building Nodejs lib" && CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ./instgo go build -o internal/core/runner/nodejs/nodejs.so -buildmode=c-shared -ldflags="-s -w" cmd/lib/nodejs/main.go && echo "Building main" && GOOS=linux GOARCH=amd64 ./instgo go build -o main -ldflags="-s -w" cmd/server/main.go echo "Building env" GOOS=linux GOARCH=amd64 ./instgo go build -o env -ldflags="-s -w" cmd/dependencies/init.go编译镜像。
以amd64为例:
docker build -t sandbox:0.2.9 -f docker/amd64/dockerfile .部署dify-sandbox应用并上报监控数据。
容器化部署
在dify-sandbox应用的YAML文件中将以下
labels添加到spec.template.metadata层级下。labels: aliyun.com/app-language: golang armsPilotAutoEnable: 'on' armsPilotCreateAppName: "dify-sandbox"非容器化部署
部署组件时请添加以下环境变量。
ARMS_LICENSE_KEY: xxx //账号对应的ARMS LicenseKey ARMS_REGION_ID: cn-heyuan //选择填写对应的region ARMS_ENABLE: true ARMS_APP_NAME: dify-sandbox您可以通过DescribeTraceLicenseKey OpenAPI获取LicenseKey。

查看dify-sandbox监控。
在应用列表页面进入dify-sandbox应用,监控详情如下:

调用链详情:

相关文档
如需指定Python探针版本,请参见如何安装指定地域与版本的探针。